Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem calling a servlet from JSP

 
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.

 
Sheriff
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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:
 
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
Posts: 21999
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
I found a beautiful pie. And a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic