| Author |
Problem calling a servlet from JSP
|
Sunni srivastav
Greenhorn
Joined: Feb 15, 2011
Posts: 22
|
|
I know this very basic but I guess I am doing something wrong in my implementation...so please help
Note:I am using eclipse IDE for my development
Project Name:Greeting
Servlet :GreetingServlet.java
index.jsp
and my web.xml
When i am deploying my project on apache tomcat in Eclipse I am getting "index.jsp" but my index.jsp does not redirect to GreetingServlet.java on submitting.
Error message is as follows:
HTTP Status 404 - /GreetingServlet
--------------------------------------------------------------------------------
type Status report
message /GreetingServlet
description The requested resource (/GreetingServlet) is not available.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
In JSP and servlets, / means the root of the web application. In HTML, / means even one level higher. To fix this, use this instead:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
jhon masco
Ranch Hand
Joined: May 13, 2010
Posts: 93
|
|
Rob Spoor wrote:In JSP and servlets, / means the root of the web application. In HTML, / means even one level higher. To fix this, use this instead:
It would not must to work if you remove "/" ???
I mean :
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
That would until you decide to move the JSP to a sub folder and forget to modify either the JSP or the servlet's URL mapping.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56163
|
|
|
Not using the context path to prefix the servlet is fragile and prone to easy breakage as pointed out.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sunni srivastav
Greenhorn
Joined: Feb 15, 2011
Posts: 22
|
|
Rob Spoor wrote:That would until you decide to move the JSP to a sub folder and forget to modify either the JSP or the servlet's URL mapping.
Rob could you please elaborate or provide me any link which could enlighten me over this discussion.Cause I would like to understand this mapping concept more..I think its the core of any web project...So any guidance would be highly appreciated.
|
 |
Sunni srivastav
Greenhorn
Joined: Feb 15, 2011
Posts: 22
|
|
|
@Rob and @jhon masco :Thanks to both of you...it worked both the ways..:)
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56163
|
|
|
As I have said, Rob's is the correct approach. Anything else may work for now but is fragile and will easily stop working when you make future changes. Do it the right way, not just the way that seems to make it work for now.
|
 |
 |
|
|
subject: Problem calling a servlet from JSP
|
|
|