This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JSP not able to find the servlet  RSS feed

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i am coding a small demo application (jsp_demo). i have a login.jsp page which got submitted to a servlet(check) present in WEB-INF classes. i am using tomcat server, but when i click on submit button in my jsp i got an error as


"HTTP Status 404 - /check" The requested resource (/check) is not available.

my code for login.jsp and check is as follows

Login.jsp----



for check.java-----



my web.xml is



my directory structure is---


[BPSouther: Nested directory structure in code tags]
[ August 21, 2006: Message edited by: Ben Souther ]
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

action="/check"



I think that you have to set the context path, so it should be "/jsp_demo/check".
If you were using EL, you could get it with ${pageContext.request.contextPath}
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Place the jsp page below the root of the application

ie,within

SampleApplication-->login.jsp

and compile the servlet and place Servlet Class file inside

SampleApplication-->WEB-INF-->classes-->check.class

In login.jsp:

<form method="GET" action="/check">

change the above code as <form method="GET" action="check">

or

<form method="GET" action="http:\\localhost:8080\SampleApplication\check">
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by arun:

<form method="GET" action="/check">
change the above code as <form method="GET" action="check">



This is correct.
The preceeding slash tells the browser to skip your context path altogether.
It would be even better to use the request object's getContextPath method to add the context path to your relative URL.

Originally posted by arun:

<form method="GET" action="http:\\localhost:8080\SampleApplication\check">



In this link, you've used back slashes.
They need to be forward slashes.

Again, reading the contextPath from the request object (rather than hard coding it) will give you a more flexible app.

Also.
It would be wise of you to pack all of your Java classes in a package.
See:
http://faq.javaranch.com/view?PackageYourBeans
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your servlet class is NOT in a package - this will cause endless trouble so you might as well fix it now.
ALL classes used in servlets and JSP should be in packages and the references in web.xml and the jsp adjusted accordingly.
This is because the JVM looks for classes in the "default" (blank) package in the "current" directory, something you have no control over in the servlet environment.
Bill
;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!