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
Solved

calling a jsp from a servlet

Posted on 2007-04-03
8
251 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example issue 6 46
hibernate example using maven 12 57
How to determine if a string is a valid SHA value 7 35
Bot application - advice 3 38
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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.

861 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