• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Mal Charlton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Gyula Klinszky
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!