| Author |
getting HTTP Status 404 - /servlet/Firstservlet error in Tomcat
|
Kondapally Ashwin
Greenhorn
Joined: May 16, 2006
Posts: 25
|
|
Hi, I want to enter a user name and password in an html page and use doPost method in one servlet and if the user name and password is correct then I want to forward to another servlet. The following is my code in this attempt. html page <html> <body> <form action = "servlet/Firstservlet" method = "post"> please enter your name <input type = "text" name = "name"> please enter your password <input type = "password" name = "password"> </form> </body> </html> Firstservlet Second servlet web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <servlet-name>Firstservlet</servlet-name> <servlet-class>Firstservlet</servlet-class> </servlet> <servlet> <servlet-name>Secondservlet</servlet-name> <servlet-class>Secondservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Firstservlet</servlet-name> <url-pattern>/servlet/Firstservlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Secondservlet</servlet-name> <url-pattern>/Secondservlet</url-pattern> </servlet-mapping> </web-app> I placed the two servlet classes in Webapps/servlet/WEB-INF/classes/servlet folder. I placed the html file in Webapps/servlet folder. I am getting an HTTP Status 404 error. Please advise. Thanks, Ashwin. [ September 13, 2006: Message edited by: Kondapally Ashwin ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
Please use UBB code tags (read this) when posting code to preserve its formatting.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Kalai Ganesh
Ranch Hand
Joined: Sep 08, 2003
Posts: 32
|
|
Hi Ashwin, If you look at the web.xml file, the <url-pattern> is not right for the second servlet. I think it's not recognizing the Secondservlet since you missed "/servlet" in the path. <servlet-mapping> <servlet-name>Firstservlet</servlet-name> <url-pattern>/servlet/Firstservlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Secondservlet</servlet-name> <url-pattern>/Secondservlet</url-pattern> </servlet-mapping> Try it with the correction. Kalai
|
 |
Kondapally Ashwin
Greenhorn
Joined: May 16, 2006
Posts: 25
|
|
I have tried and still getting the same error. Please advise.
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
Hi Ashwin. I would have done the following things incase I would have been in your case. Check the tomcat log for the errors that the container is facing. you can put some SOP/log for cheking exactly where the flow is going. One such SOP you can put before if (name.equals("anji") && password.equals("reddy")) this will let you knwo whether its has reached the this point.If it has reached then there is some problem with the second servlet. Another tips (not related to this ..but might be useful in debugging errors of error code 500.) put the complete block of code in try{ .. .. .. }catch(Exception e){ e.printStackTrace(); } please let me know if this helps. rahul.rec.dgp@gmail.com
|
Rahul Bhattacharjee
LinkedIn - Blog
|
 |
Kondapally Ashwin
Greenhorn
Joined: May 16, 2006
Posts: 25
|
|
Hi Rahul, Thanks for your wonderful advice. It will be a great help to me in the future in debugging. But I can't get where the SOP will be printed? I have checked the Tomcat screen and could't find any messages. FYI I am using a short cut for starting and shutting down Tomcat and cannot see any messages. Thanks, Ashwin.
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
I think that is the reason.If your flow would have reached then you probably might have seen SOP on console.No SOP means your flow has not been encountered. Did the tomcat log help you.Did you see something there. Ram: How will javascript going to help in the problem.
|
 |
Arun Chidambaram
Greenhorn
Joined: Sep 16, 2006
Posts: 2
|
|
Ashwin, As you are putting FirstServlet in classes/servlet folder, it can be reached by passing through its package, in this case it should be accessed in the form of servlet.FirstServlet, change the entry in <servlet-class>Firstservlet</servlet-class> to <servlet-class>servlet.Firstservlet</servlet-class> & include package statement in corresponding class file(i.e package servlet) Hope this solves the issue  [ September 16, 2006: Message edited by: ArunChidam ]
|
Arun Chidambaram<br />SCJP1.4, SCWCD1.5
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
Yes Ashwin , Arun C has the catch.While writing the servlet you are using the default package but you are putting the classes in /classes/servelt which is like the package of the classes is servlet(which is not true). What you can do is recompile the java classes with package servlet; and follow the usual steps.
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Arun C. You have been asked twice to ajust your screen na e to mee the JavaRanch Naming Policy You can change it here This your third warning. Be aware, accounts with invalid screen names get deleted after three warnings.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
 |
|
|
subject: getting HTTP Status 404 - /servlet/Firstservlet error in Tomcat
|
|
|