calling a jsp from a servlet

Hi guys:

Well I have a servlet  (servlet/CommandDo) and also an jsp file (dataEntry.jsp) well this jsp call it self to update some html select controls values  (country--->state--citiy).
after some validation process I call the jsp file from the servlet usign the dispatcher method  (/dataEntry.jsp or /myapplication/dataEntry.jsp) but I clearly notice that I'm out of the context cause I don't get the styles of the CSS wich path is relative and when I want to update the controt values (I select a country and the jsp call itsefl to update the state control  by  submitting  the form and the location is "dataEntry.jsp")  I get an error cause It says that I'm still at  the servlet context " servlet/dataEntry.jsp   not found" and they are right!!!  What should I do ??? (I've already tried with the response.sendRedirect()  method)
edwbear1976aAsked:
Who is Participating?
 
KuldeepchaturvediCommented:
/myapplications/dataentry.jsp should get to the jsp..
0
 
KuldeepchaturvediCommented:
you need to change your paths to be relative from the application root...

like the form location should be "/myapplication/dataEntry.jsp"..
same thing for your CSS etc..

when you use the requestdispatcher.. its a server side redirect.. which means for the browser.. the context is still in servlet and does not change even if the request is redirected to the jsp..
0
 
Ajay-SinghCommented:
I would suggest to *always* refer the css and other static contents using absolute paths.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Mayank SAssociate Director - Product EngineeringCommented:
>> (I've already tried with the response.sendRedirect()  method

that won't work for you anyway, if you set some request attributes in the servlet and need them.

For CSS inside the JSP, you can use context.getRealPath () to resolve the correct path for images and CSS
0
 
edwbear1976aAuthor Commented:
Hi guys and thanx for your responses.
well about relative or static path. Kuldeepchaturvedi recommends relative paths but Ajay-Singh suggests that always to set paths as absolutes..
mayankeagle when you say about the send.redirect() method :
<<that won't work for you anyway, if you set some request attributes in the servlet and need them.>>
well then what is the solution that you would suggest, if I 've got  to use the dispatcher what should be the correct url ?  to go from  myServlet.class to my dataEntry.jsp
=============================
(folder are on UPPERCASES)
JAKARTA XXXXX
       
APPLICATIONS
                  MYAPPLICATIONS
                   dataEntry.jsp
                   WEB-INF
                                   CLASSES
                                   myServlet.class

=============================================
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> well then what is the solution that you would suggest, i

What is the URL pattern for the servlet in your web.xml/
0
 
edwbear1976aAuthor Commented:
Hi and thax for your comments
well the servlet-mapping tag is :  
/servlet/myServlet
0
 
edwbear1976aAuthor Commented:
well it is in fact :

servlet/CommandDo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.