File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes A jsp and a servlet calling each other repeatedly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "A jsp and a servlet calling each other repeatedly" Watch "A jsp and a servlet calling each other repeatedly" New topic

A jsp and a servlet calling each other repeatedly

Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Hi my professional Friends
I have a jsp and a servlet(IDE: Oracle9i Jdeveloper).
1-submiting a request from jsp to servlet, using the following address:
2-dispatching the recieved request to the very same jsp again:
RequestDispatcher dispatcher =
dispatcher.forward(req, res);
3-Again,repeating the stage number 1
For the first time the JSP finds Servlet but for the second time after no-3 I get ERROR since there is an extra "servlet" attached to the servlet's url like this:
Resource /Workspace1-Project1-context-root/servlet/servlet/Pkg_Servlets.Srv_Srv1 not found on this server
Thank you for any hint and advice.
Best Regards,
[ December 17, 2002: Message edited by: Pourang Emami ]

Best Regards,<br />Pourang Emami
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Indeed. This is a big issue with me and makes the software dictate the layout of the web pages to a degree. I dont like that much.

This is a problem with resolution of names between servlets and JSPs.
You probably used relative linking from your JSP. When a servlet forwards to a JSP it does NOT change the address in address bar. More importantly, the web page has a new root.
if web page is here
and servlet is here
all relative links in the jsp page will be relative to the servlets location that forwarded you to that page.
so if your relative link before resolved like this
it will now resolve like this
because its now in the servlets context. (which is now a bad link)
Easiest solution is to just make the servlet and the jsp in the same directory When servlets forward to other directories, they make all relative links on the target page relative to that servlet's location.

I map my servlets to *.servletName so they will exist in all directories. Then I reach them by href="1.servletName". that way the context remains the same as the JSP. so when I forward back to that same jsp it works ok. Still their is a problem if you try to forward to a different directory than the servlet was addressed from. Dont know a good way around this.
Pourang Emami
Ranch Hand

Joined: Sep 21, 2002
Posts: 127
Dear CL
Although still some how confused, but thank you so much for your detailed profesSional reply.
Seems like a BIG BUG in an Enterprise Solution(J2EE).
See u around in the saloon.
I agree. Here's the link:
subject: A jsp and a servlet calling each other repeatedly
It's not a secret anymore!