• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem calling a servlet from JSP

 
Greenhorn
Posts: 24
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 101
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Rob and @jhon masco :Thanks to both of you...it worked both the ways..:)
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Not so fast naughty spawn! I want you to know about
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic