Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > RequestDispatcher and usage of forward slash

Reply
Thread Tools

RequestDispatcher and usage of forward slash

 
 
harryos
Guest
Posts: n/a
 
      12-16-2008
While trying out a tutorial about RequestDispatcher ,I came across
some servlet code like this

doGet(...) {
....
RequestDispatcher dispatcher =request.getRequestDispatcher("/
viewPostedData.jsp?"+querystr);
dispatcher.forward(request,response);

}

When I tried this with
request.getRequestDispatcher("viewPostedData.jsp?" +querystr);

I found that the servlet invokes the viewPostedData.jsp with the given
query string.So what was the need for a '/' in front of the name of
the jsp file?

Can somebody clarify this?
thanks,
harry

 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      12-16-2008
harryos wrote:
> While trying out a tutorial about RequestDispatcher ,I came across
> some servlet code like this
>
> doGet(...) {
> ....
> RequestDispatcher dispatcher =request.getRequestDispatcher("/
> viewPostedData.jsp?"+querystr);
> dispatcher.forward(request,response);
>
> }
>
> When I tried this with
> request.getRequestDispatcher("viewPostedData.jsp?" +querystr);
>
> I found that the servlet invokes the viewPostedData.jsp with the given
> query string.So what was the need for a '/' in front of the name of
> the jsp file?
>
> Can somebody clarify this?
> thanks,
> harry
>

A leading "/" specifies that the path isn't relative to the current
request. I believe if you *do* use /, then it is relative to the servlet
context, but I could be wrong, I don't often mess with that level,
leaving it happily abstracted by Spring

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      12-17-2008
harryos wrote:
>> While trying out a tutorial about RequestDispatcher ,I came across
>> some servlet code like this
>>
>> doGet(...) {
>> ....
>> RequestDispatcher dispatcher =request.getRequestDispatcher("/
>> viewPostedData.jsp?"+querystr);
>> dispatcher.forward(request,response);
>>
>> }
>>
>> When I tried this with
>> request.getRequestDispatcher("viewPostedData.jsp?" +querystr);
>>
>> I found that the servlet invokes the viewPostedData.jsp with the given
>> query string.So what was the need for a '/' in front of the name of
>> the jsp file?
>>
>> Can somebody clarify this?


Daniel Pitts wrote:
> A leading "/" specifies that the path isn't relative to the current
> request. I believe if you *do* use /, then it is relative to the servlet
> context, but I could be wrong, I don't often mess with that level,
> leaving it happily abstracted by Spring


I decided to do something truly radical and look at the Javadocs for the
method (gasp!):
<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang .String)>
wherein they tell us:
> The pathname specified may be relative, although it cannot extend outside the
> current servlet context. If the path begins with a "/" it is interpreted as
> relative to the current context root.


JAYF.

I remain somewhat surprised that people don't look there first.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
jsp include or RequestDispatcher.forward() need to identify 301's christopher@dailycrossword.com Java 0 08-29-2009 09:44 PM
string translate, replace, find and the forward slash destroooooy Python 4 04-29-2008 09:46 PM
RequestDispatcher.forward() not throwing IllegalStateException. Jan van Mansum Java 0 07-23-2006 10:18 AM
Question about Servlet's RequestDispatcher forward / file paths Harry Java 1 12-22-2005 02:40 PM
RequestDispatcher.forward() Taking 30 Seconds Each Will Handley Java 1 12-10-2003 11:52 AM



Advertisments