Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP not able to find the servlet  RSS feed

 
sachin yadav
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 ]
 
Christophe Verré
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}
 
Arun Prasath
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">
 
Ben Souther
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
 
William Brogden
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!