Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with request.getContextPath()

 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic