Solved

calling a jsp from a servlet

Posted on 2007-04-03
8
249 Views
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)
0
Comment
Question by:edwbear1976a
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 150 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..
0
 
LVL 23

Assisted Solution

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

Assisted Solution

by:Mayank S
Mayank S earned 75 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
0
 

Author Comment

by:edwbear1976a
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)
JAKARTA XXXXX
       
APPLICATIONS
                  MYAPPLICATIONS
                   dataEntry.jsp
                   WEB-INF
                                   CLASSES
                                   myServlet.class

=============================================
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 75 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/
0
 

Author Comment

by:edwbear1976a
ID: 18874440
Hi and thax for your comments
well the servlet-mapping tag is :  
/servlet/myServlet
0
 

Author Comment

by:edwbear1976a
ID: 18874446
well it is in fact :

servlet/CommandDo
0
 
LVL 19

Accepted Solution

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 38
topping2 challenge 13 80
backtracking recursion  code 19 53
java stored proc example 9 21
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now