| Author |
http 404 error
|
budsy remo
Ranch Hand
Joined: Sep 20, 2008
Posts: 103
|
|
i m new to mvc design and tomcat , 1. i hav made a deployemnt environment which is "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Beer-v1" 2. inside the Beer-v1 i hav put form.html here's the code for form.html <html> <body> <h1 align="center">Beer Selection</h1> <form method="post" action="/Beer-v1/SelectBeer"> Select Beer Characteristics <p> Color : <select name="color" size="l"> <option value="light">light</option> <option value="green">green</option> <option value="brown">brown</option> <option value="amber">amber</option> <option value="dark">dark</option> </select> <br> <center> <input type="Submit" value="submit"> </center> </form> </body> </html> 3. Directory of web.XML "C:\Program Files\Apache Software Foundation\Tomcat5.5\webapps\Beer-v1\WEB-INF" 4. The servlet the post method will call(it compiles whout ne error) package com.example.web; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class beer extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("Beer Selection Advice<br>"); String c=req.getParameter("color"); out.println("<br>Got Beer Color"+c); } } 5. the web .xml file <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" 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"> <servlet> <servlet-name>beer</servlet-name> <servlet-class>com.example.web.beer</servlet-class> </servlet> <servlet-mapping> <servlet-name>beer</servlet-name> <url-pattern>/SelectBeer</url-pattern> </servlet-mapping> </web-app> 6. beer.class file's directory "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\Beer-v1\WEB-INF\classes\com\example\web" 7. now wen i run the server and type "http://localhost:8080/Beer-v1/form.html" on the browser i see the form but when i click the submit button i get http error 404 or should i say SelectBeer.do not found .help me please
|
 |
budsy remo
Ranch Hand
Joined: Sep 20, 2008
Posts: 103
|
|
I know that my problem is big but i just wanted to give you full details i am stuck in this problem for quite a long time that's why. I m also giving details of all the environment variables set for my computer. CLASSPATH C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar JAVA_HOME C:\Program Files\Java\jdk1.6.0_07 PATH C:\Program Files\Java\jdk1.6.0_07\bin TOMCAT_HOME C:\Program Files\Apache Software Foundation\Tomcat 5.5
|
 |
aleem khan
Ranch Hand
Joined: Aug 07, 2008
Posts: 94
|
|
|
I think it is some package problem i too had faced this problem once, i suggest you to remove all the package references like com.example.web; and use everything as default..also change the same in web.xml etc..it will definetely work
|
SCJP(1.4), SCWCD, Oracle 9i SQL certified, Oracle PLSQL Developer Certified Associate
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
Originally posted by aleem khan: I think it is some package problem i too had faced this problem once, i suggest you to remove all the package references like com.example.web; and use everything as default..also change the same in web.xml etc..it will definetely work
Huh? Definitely not! Do not move your classes to the default package -- quite the opposite. Never use the default package for servlets or beans to be used in a web application. Never!
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
aleem khan
Ranch Hand
Joined: Aug 07, 2008
Posts: 94
|
|
Infact i am able to run your programme successfully web.xml -------- <?xml version="1.0" ?> <!--/** * Copyright (c) 2005 by David Bridgewater * All rights reserved. * * You may study, use, modify, and distribute this * software for any purpose provided that this * copyright notice appears in all copies. * * This software is provided without warranty * either expressed or implied. */--> <web-app version="2.4" 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"> <servlet> <servlet-name>beer</servlet-name> <servlet-class>com.example.web.beer</servlet-class> </servlet> <servlet-mapping> <servlet-name>beer</servlet-name> <url-pattern>/beer</url-pattern> </servlet-mapping> </web-app> beer.java --------- package com.example.web; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class beer extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("Beer Selection Advice<br>"); String c=req.getParameter("color"); out.println("<br>Got Beer Color"+c); } } form.html ---------- <html> <body> <h1 align="center">Beer Selection</h1> <form method="post" action="/test/beer"> Select Beer Characteristics <p> Color : <select name="color" size="l"> <option value="light">light</option> <option value="green">green</option> <option value="brown">brown</option> <option value="amber">amber</option> <option value="dark">dark</option> </select> <br> <center> <input type="Submit" value="submit"> </center> </form> </body> </html> All the remaining parameters are same , Only i have put everything under directory "test" which is under "webapp"
|
 |
aleem khan
Ranch Hand
Joined: Aug 07, 2008
Posts: 94
|
|
Thanks bear for your concern, i just told to remove package name because it is the first servlet for the person who is asking and often i have experienced that for beginers it is difficult to compile/run programme with package..once they succeed in default then they can try with packages... this is because i myself struggled a lot when i compiled HelloWorld.java for the first time with a package ...then i removed the package and all it started working ...
|
 |
budsy remo
Ranch Hand
Joined: Sep 20, 2008
Posts: 103
|
|
aleem thanks for your time man could you tell me where should i do the changes exactly?? I mean being new which all files should i modify?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
Originally posted by aleem khan: i just told to remove package name because it is the first servlet for the person who is asking and often i have experienced that for beginers it is difficult to compile/run programme with package
This is poor advice. Often, the lack of packaged classes is the cause of problems. It's also not a good idea to get people into bad habits just to get something to work. Learning how to properly compile packages classes is an important part of Java and should not be skipped in the interest of false progress.
|
 |
Manoj Jain
Greenhorn
Joined: Sep 16, 2008
Posts: 2
|
|
The only change you have to make is in the following line : <form method="post" action="/Beer-v1/SelectBeer"> instead: <form method="post" action="/Beer-v1/beer"> Your application should run. Further, Bear - instead of giving your comments on Programming style of other person - you should provide the solution to the problem. Thanks
|
 |
 |
|
|
subject: http 404 error
|
|
|