Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A jsp and a servlet calling each other repeatedly

 
Pourang Emami
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic