calling a jsp from a servlet

Posted on 2007-04-03
Medium Priority
Last Modified: 2013-11-24
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)
Question by:edwbear1976a
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 19

Assisted Solution

Kuldeepchaturvedi earned 600 total points
ID: 18847539
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..
LVL 23

Assisted Solution

Ajay-Singh earned 100 total points
ID: 18848336
I would suggest to *always* refer the css and other static contents using absolute paths.
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 300 total points
ID: 18861425
>> (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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.


Author Comment

ID: 18874365
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)

LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 300 total points
ID: 18874418
>> well then what is the solution that you would suggest, i

What is the URL pattern for the servlet in your web.xml/

Author Comment

ID: 18874440
Hi and thax for your comments
well the servlet-mapping tag is :  

Author Comment

ID: 18874446
well it is in fact :

LVL 19

Accepted Solution

Kuldeepchaturvedi earned 600 total points
ID: 18874714
/myapplications/dataentry.jsp should get to the jsp..

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question