This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JSP and the fly likes problem with request.getContextPath() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "problem with request.getContextPath()" Watch "problem with request.getContextPath()" New topic
Author

problem with request.getContextPath()

Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

One of my friend told that, the JSP page will not be traslated if following line is included in JSP.

<%=request.getContextPath()%>

is he correct ? or any other problem is associated with this ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56540
    
  14

Did you try it? Did you ask him what the issue might be?

How else, at least using scriplets, would you expect to obtain the context path?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Originally posted by Bear Bibeault:
Did you try it? Did you ask him what the issue might be?

How else, at least using scriplets, would you expect to obtain the context path?


Some of the forums says, the JSP page will be translated every time, if it see that method() ...

Is it true ?
[ February 09, 2007: Message edited by: Srinivas Kalvala ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56540
    
  14

You can easily test that as well.

But as an academic exercise, why would you (or anyone) believe that just calling a method, just like any other method, would trigger a retranslation?
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Can you tell me, how can we test that one ?

Or

Can you tell me, the problems that can occur with the use of request.getContxtPath() in jsp directly ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56540
    
  14

Originally posted by Srinivas Kalvala:
Can you tell me, how can we test that one ?
?


Use the scriptlet expression in a page and see if a new servlet is generated on behalf of the JSP whenever it is accessed. You will find that it will not.

Can you tell me, the problems that can occur with the use of request.getContxtPath() in jsp directly


None. In fact, you must use the context path when creating correct server-relative URLs.

Though I do recommend that scriplet expression be avoided under the JSP 2.0 environment in favor of the EL equivalents.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: problem with request.getContextPath()
 
Similar Threads
problem with RequestDispatcher
simple relative path img
Custom Tag problem in JSP
Placing a pdf under WEB-INF/classes and accessing it through relative url
Sessions on a servlet