Solved

calling a jsp from a servlet

Posted on 2007-04-03
8
248 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:mayankeagle
mayankeagle 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

707 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

15 Experts available now in Live!

Get 1:1 Help Now