• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

http 404 error

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic