• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp > servlet > jsp......URLs???

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi fellow ranchers,
here's my scenario:
1) client accesses JSP1 directly (ie. specifies the URL of JSP1 in the browser).
2) a form on JSP1 calls MyServlet which then forwards the request back to JSP1.
The flow is working okay, but there's a problem when JSP1 references other JSPs.
If JSP1 uses a relative path eg...
<A href="other.jsp">Link</A>
then it works fine when JSP1 is accessed directly by the client (part 1 above). But when JSP1 is returned via MyServlet (step 2 above), then the link will look for "other.jsp" in a directory relative to the location of MyServlet.
my question is:
when writing JSP1, what is the best way to reference other JSPs?
this has been driving me nuts and i hope someone can help.
regards
Malcolm
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Malcolm,
I had the same problem, which I discovered much later in the middle of my project. My solution was to use 'within-site absolute' addressing, like this:
<a href='/otherdir/other.jsp'>link</a>
This solves the problem with current directory changing, and still kind of relative addressing, which helps you if you want to deploy the application on different servers, ports, or protocolls (e.g. https).
Regards:
-Gyula
 
Mal Charlton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Gyula
Thanks for your reply. For your project, were you working in the root context?
I think i already tried your good suggestion a while ago , but found that i also had to specify the context for step 1 (see original post) to work.
However, when the servlet uses its RequestDispatcher to forward to the JSP (step 2), the context would appear twice in the URL, thus the link was invalid.
I'm not 100% sure, but i think this was what happened. I'l have to try it again tonight.
Malcolm
 
reply
    Bookmark Topic Watch Topic
  • New Topic