Re: jsps not serving from context root in netbeans server
- From: Dundonald <mark.dundon@xxxxxxxxx>
- Date: Fri, 12 Oct 2007 00:25:01 -0000
Lew wrote:
Dundonald wrote:
Yes I've been doing some googling and RTFMing as you advised ;) (well
I was doing that anyway) but I must admit despite reading the API and
a couple sites found on google so far it's still not clear how use of
this method can help with maintaining context root. I may well be
missing something.
My main points have to do with keeping the request and avoiding the round trip
to the client.
HttpServletResponse.sendRedirect() tells us that, "[i]f the location is
relative without a leading '/' the container interprets it as relative to the
current request URI. If the location is relative with a leading '/' the
container interprets it as relative to the servlet container root."
The leading '/' moves the redirect out of the context. I'm thinking that the
"current request URI" includes not only the application context root but the
specific resource handling the request. You might need to prefix the redirect
URL with "../".
However, I will say that most of what people want to do with a redirect is
better handled by the forward mechanism.
OK I've been doing some more reading of the APIs. I now understand
completely. The forward vs a redirect aside (as in the fact that the
redirect sends a response back to the browser to then send another
request for a specific resource), I now also understand about the
context root.
I have done some digging and a response.sendRedirect is still possible
IF the request.getContextPath() method is used to suppliment the jsp
name so for example:
resp.sendRedirect( resp.encodeURL( req.getContextPath() +
getJspNameToSendInResponse() ) )
or and as you have suggested I have also got it working with:
getServletContext().getRequestDispatcher(getJspNameToSendInResponse()).forward(getCurrentHttpServletRequest(),
resp);
where the current context of the current servlet is used to obtain the
dispatcher and then forward on.
Thanks!
So the only question I have now is, I'm assuming of course that the
encodeURL as used in the sendRedirect example is negligible in the
request dispatcher forward case?
.
- Follow-Ups:
- References:
- jsps not serving from context root in netbeans server
- From: Dundonald
- Re: jsps not serving from context root in netbeans server
- From: Dundonald
- Re: jsps not serving from context root in netbeans server
- From: Lew
- Re: jsps not serving from context root in netbeans server
- From: Dundonald
- Re: jsps not serving from context root in netbeans server
- From: Chris ( Val )
- Re: jsps not serving from context root in netbeans server
- From: Dundonald
- Re: jsps not serving from context root in netbeans server
- From: Lew
- Re: jsps not serving from context root in netbeans server
- From: Dundonald
- Re: jsps not serving from context root in netbeans server
- From: Lew
- jsps not serving from context root in netbeans server
- Prev by Date: Re: J2EE - How to share tomcat sessions across multiple IE windows
- Next by Date: Re: jsps not serving from context root in netbeans server
- Previous by thread: Re: jsps not serving from context root in netbeans server
- Next by thread: Re: jsps not serving from context root in netbeans server
- Index(es):
Relevant Pages
|