Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getContextPath not applicable to HttpSession

 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p. 222 of Head First Servlet, only HttpServletRequest can have getContextPath () (the request URI that indicates the context).


According to p.198,
a session is an object used to maintain conversational state with a client
.
Why HttpSession does not have this method ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65658
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would it?

(Hint: you can get it from other information you can get from the session.)
 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it because each request within a session has different context path ?
In the other words, a session may have different context path for different requests?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65658
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The context path is fixed for the application.

The reason is, as I hinted, it's already available from information that the session returns so a method would be redundant. Look at the javadoc carefully (and deeply).
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!