This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Problem calling a servlet from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem calling a servlet from JSP" Watch "Problem calling a servlet from JSP" New topic
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: 19679
    
  18

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 - OCEEJBD 6
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: 19679
    
  18

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: 61092
    
  66

Not using the context path to prefix the servlet is fragile and prone to easy breakage as pointed out.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 61092
    
  66

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem calling a servlet from JSP