<jsp:forward> tag cannot change the current URL?

M

Matt

I want to ask if <jsp:forward> tag cannot change the current URL? What
if I want the URL changed?

I hava a jsp page to forward to different pages based on conditions as
follows:

<%
if (cond1)
{
%>
<jsp:forward page="page1.jsp"/>
<% }
else if (cond2)
{
%>
<jsp:forward page="page2.jsp"/>
<% }
else
{
%>
<jsp:forward page="page3.jsp"/>
<% } %>

Any suggestions? Please advise. Thanks!!
 
T

Tor Iver Wilhelmsen

I want to ask if <jsp:forward> tag cannot change the current URL?

<jsp:forward> - or what it really is, RequestDispatcher.forward() - is
only a server-side forwarding. The browser interacts with your JSP,
not the forwarded-to resources.

My bet is you are really looking for ye ole' servlet API's
response.sendRedirect() instead, which sends a HTTP forward to the
browser.
 
R

RobM

Matt said:
I want to ask if <jsp:forward> tag cannot change the current URL? What
if I want the URL changed?

I hava a jsp page to forward to different pages based on conditions as
follows:

<%
if (cond1)
{
%>
<jsp:forward page="page1.jsp"/>
<% }
else if (cond2)
{
%>
<jsp:forward page="page2.jsp"/>
<% }
else
{
%>
<jsp:forward page="page3.jsp"/>
<% } %>

Any suggestions? Please advise. Thanks!!

Hi Matt
That's correct. It doesn't change the URL on the browser - its still the
same URL to get to your script above. If you want page2/page3 etc to show in
the URL of the browser you have to use response.sendRedirect. But that's a
round trip to the browser and back, whereas you're already there with
<forward> - do you really need to?

Cheers
Rob
Melbourne Oz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,269
Messages
2,571,099
Members
48,773
Latest member
Kaybee

Latest Threads

Top