Regarding JSP

I am new to JSP & Servlet technology. while forwarding request to next page using "forward action" or using response.sendRedirect(URL) method of servlet, destination page's URL address is not displayed in the address line of the browser. how can i get it displayed in the address line of the browser?

[320 byte] By [vidhyass] at [2007-9-26 3:09:09]
# 1
pls send me your code snippet-babu
babukri at 2007-6-29 11:14:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

First, I tried as :

<jsp:forward page="/Business.jsp" />

Forwarded to next page(Business.jsp), but

the url http://localhost:7001/Business.jsp didn't appear in address bar of the browser.

Second, I tried this:

<% response.sendRedirect("http://localhost:7001/Business.jsp"); %>

Third, I set the location header before forwarding to next page.

<%

response.setHeader ("Location","http://localhost:7001/Business.jsp");

%>

<jsp:forward page="/Business.jsp" />

If you could please tell me the solution.

vidhyass at 2007-6-29 11:14:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> <jsp:forward page="/Business.jsp" />

> Forwarded to next page(Business.jsp), but

> the url http://localhost:7001/Business.jsp didn't

> appear in address bar of the browser.

It won't - JSP forwarding is a way to include external content in this request without requiring the browser to generate a new request. The fact that the content is hidden is a good thing - it is possible to forward and include many times. This allows one piece to act as a dispatcher for other pieces.

> Second, I tried this:

> <%

&gt; response.sendRedirect("http://localhost:7001/Business.j

&gt; p"); %>

There is no reason that shouldn't have worked, unless the URL is not correct or your browser is weird about redirecting. This might not have worked because the response was already committed, which means that the headers had already been dispatched so no redirect was possible. Try doing it in a servlet, or before any content is written. In your above example it is likely that the response would have been committed.

> Third, I set the location header before forwarding to

> next page.

> <%

&gt; response.setHeader

&gt; ("Location","http://localhost:7001/Business.jsp");

&gt; %>

Never seen that before. I don't think that affects the address bar in the browser anyway.

> <jsp:forward page="/Business.jsp" />

If you want the user to see your URL, just direct them straight to the page you want them to see instead of forwarding.

smiths at 2007-6-29 11:14:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...