aspose file tools*
The moose likes JSP and the fly likes problem with request.getContextPath() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
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: 61010
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 61010
    
  65

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: 61010
    
  65

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.
 
Consider Paul's rocket mass heater.
 
subject: problem with request.getContextPath()