• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem calling a servlet from JSP

 
Sunni srivastav
Greenhorn
Posts: 24
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSP and servlets, / means the root of the web application. In HTML, / means even one level higher. To fix this, use this instead:
 
jhon masco
Ranch Hand
Posts: 98
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not using the context path to prefix the servlet is fragile and prone to easy breakage as pointed out.
 
Sunni srivastav
Greenhorn
Posts: 24
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob and @jhon masco :Thanks to both of you...it worked both the ways..:)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic