absolute path versus relative path in JSP

M

Matt

absolute path versus relative path in JSP

I have an index.jsp that will forward to different JSP pages
based on different conditions:

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


The problem is in different pageX.jsp, when user submit form data, it will go to
other pages. Before, the index.jsp is in the same directory as pageX.jsp.
But now I moved out ofthe address folder, and it has broken links.

In my case, should I specify the abosolute path, rather than relative path?
so that in whatever situation, it will work.

please help. thanks!!
 
J

John C. Bollinger

Matt said:
absolute path versus relative path in JSP

I have an index.jsp that will forward to different JSP pages
based on different conditions:

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


The problem is in different pageX.jsp, when user submit form data, it will go to
other pages. Before, the index.jsp is in the same directory as pageX.jsp.
But now I moved out ofthe address folder, and it has broken links.

In my case, should I specify the abosolute path, rather than relative path?
so that in whatever situation, it will work.

If it is important that the browser know which resource actually
delivers the response (i.e. that the response came from
address/page3.jsp rather than from index.jsp) then you need index.jsp to
redirect instead of forwarding. [response.sendRedirect(...);] In that
case, the browser will resolve URLs relative to address/pageX.jsp
instead of relative to index.jsp, which may solve your problem. Another
alternative would be to put a <base> element in the html <head> of the
response, in which you specifies the correct URL against which to
resolve relative URLs.

If neither of those suggestions is helpful then I guess I don't
understand the problem well enough. A minimal, self-contained example
would illustrate the problem well enough to elicit better targeted
responses.


John Bollinger
(e-mail address removed)
 
M

Matt

thanks!!

response.sendRedirect(URL); is working for me now.

One problem though, because there is another jsp page from other
machine that will call index.jsp (other page->index.jsp -> page1.jsp).
And in page1.jsp, it has code: request.getParameter("state");, now the
data is null. But if I use <jsp:forward page="page1.jsp"/>, it can
resolve this problem but it creates the broken link problem.

Are there any workarounds that I can use response.sendRedirect(...)
but still able to pass the data to page1.jsp.

any ideas? thanks!
 
S

Sudsy

Matt wrote:
One problem though, because there is another jsp page from other
machine that will call index.jsp (other page->index.jsp -> page1.jsp).
And in page1.jsp, it has code: request.getParameter("state");, now the
data is null. But if I use <jsp:forward page="page1.jsp"/>, it can
resolve this problem but it creates the broken link problem.

Are there any workarounds that I can use response.sendRedirect(...)
but still able to pass the data to page1.jsp.

any ideas? thanks!

Stuff it in the session context and extract accordingly.
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top