The word "world" (κοσμος) can have a number of meanings other than "every human being without exception," which is how it is often taken. A.W. Pink maintained that there are 7 uses for the word "world" and John Own offered (I believe) 16.
In John's gospel there are a few meanings present, ranging from "every human being without exception" to "all nations of the earth" to "non-elect humanity." In John 3:16, I believe John is referring to this first use, reflecting a real love of God for all that he has made, and to the universal call to repentance and faith in Christ. In John 17:9, however, he is speaking about the world which does not (and will not–John 17:20) believe in him for salvation, or "non-elect humanity."
The importance of this is that Jesus intercession and prayer are tied to his sacrifice. As the High Priest of our confession (Hebrews 3:1), his prayers for his own will be as effective as his sacrifice for them. Jesus prays for his own, and not the world, and his prayer is heard.
Does that help?