File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
Author

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).
**senario:
1-submiting a request from jsp to servlet, using the following address:
servlet/Pkg_Servlets.Srv_Srv1
2-dispatching the recieved request to the very same jsp again:
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/untitled1.jsp");
dispatcher.forward(req, res);
3-Again,repeating the stage number 1
**Problem:
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,
Pourang
[ 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
http://serverPages/myDirectory/aJSP.jsp
and servlet is here
http://servlet/aServlet
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
href="aJSP.jsp"
http://serverPages/myDirectory/aJSP.jsp
it will now resolve like this
http://servlet/aJSP.sjp
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.
Regards,
Pourang
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A jsp and a servlet calling each other repeatedly