Forums Register Login

A jsp and a servlet calling each other repeatedly

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 748 times.
Similar Threads
Connection with servlets (jsp)
Returning ResultSet from servlet to jsp ->NullPointerException
RequestDispatcher URLrewrite SessionID
RequestDispatcher forward not displaying jsp page
Need to hook two servlets together, how do I do that?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:41:49.