absolute path versus relative path in JSP

Discussion in 'Java' started by Matt, Jul 8, 2004.

  1. Matt

    Matt Guest

    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!!
    Matt, Jul 8, 2004
    #1
    1. Advertising

  2. Matt wrote:

    > 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
    John C. Bollinger, Jul 8, 2004
    #2
    1. Advertising

  3. Matt

    Matt Guest

    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!
    Matt, Jul 8, 2004
    #3
  4. Matt

    Sudsy Guest

    Matt wrote:
    <snip>
    > 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.
    Sudsy, Jul 8, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Guettler
    Replies:
    3
    Views:
    741
    Andrei
    Oct 27, 2003
  2. Jason R. Coombs

    Relative versus absolute paths on Windows

    Jason R. Coombs, Nov 19, 2009, in forum: Python
    Replies:
    5
    Views:
    908
    Nobody
    Nov 24, 2009
  3. Nigel Wilkinson
    Replies:
    2
    Views:
    375
    Nigel Wilkinson
    Jul 25, 2005
  4. Paul Butcher
    Replies:
    12
    Views:
    692
    Gary Wright
    Nov 28, 2007
  5. James Byrne
    Replies:
    3
    Views:
    543
    James Byrne
    Sep 14, 2010
Loading...

Share This Page