Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"The requested resource is not available" 404 error

 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- Working on simple example from O'Reilley Heads First Servlets, web.xml not getting called.
Tomcar home folder D:\owner\Java Progs\apache-tomcat-7.0.12\bin
Flow of sequence is beet.html->web.xml> removed folder structures.
Attached html,web.xml and servlet.java
If someone can guide would be helpful. HelloWorld test servlets working fine so other servlets examples shipped with container, the webcontainer Beer1 getting hit and beer.html getting displayed.
However get error "type Status report
message /BeerSelect.do
description The requested resource (/BeerSelect.do) is not available."



Beer.html
<html><body>
<h1 align="center">Beer Selection Page</h1>
<form method="POST" action="BeerSelect.do">
<center>
Select beer characteristics <p>
Color:
<select name="color" size="1">
<option value="light">light</option>
<option value="amber">amber</option>
<option value="brown">brown</option>
<option value="dark">dark</option>
</select>
<br><br>

<input type="SUBMIT">
</center>

</form></body>
</html>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>BeerSelect</servlet-name>
<servlet-class>BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>BeerSelect</servlet-name>
<url-pattern>/BeerSelect.do</url-pattern>
</servlet-mapping>

</web-app>

BeerSelect.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException,ServletException {
res.setContentType("text/html");
PrintWriter out= res.getWriter();
out.println("Beer Selection Advice<br>");
String c = req.getParameter("color");
out.println("<br> got beet color"+c);
}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This really should be a FAQ - your problem is due to the servlet class not defined in a package.



ALL classes used in servlets or jsp MUST be in a package - the reason being that the JVM looks for classes not in a package in the "current directory" - something you have not control over.

Lots of posts in this forum with 404 error in the title.

Bill
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eerlier put classes in folder structure.
The folder struc: D:\owner\Java Progs\apache-tomcat-7.0.12\webapps\Beer1\WEB-INF\classes\com\examples\web
Modified web.xml and Java Class file. Also compile the class from root WEB-INF directory.
Know simple example yer tried hours to figure it out.
Thanks

<?xml version="1.0" encoding="UTF-8"?>
<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>BeerSelect</servlet-name>
<servlet-class>com.examples.web.BeerSelect</servlet-class>
</servlet>

package com.examples.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException,ServletException {
res.setContentType("text/html");
PrintWriter out= res.getWriter();
out.println("Beer Selection Advice<br>");
String c = req.getParameter("color");
out.println("<br> got beet color"+c);
}
}
<servlet-mapping>
<servlet-name>BeerSelect</servlet-name>
<url-pattern>/BeerSelect.do</url-pattern>
</servlet-mapping>

</web-app>
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error occurs after hitting Submit button of beer.html file. index.html abd beer.html from D:\owner\Java Progs\apache-tomcat-7.0.12\webapps\Beer1 gets displayed successfully.
thks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you worked through the suggestions in the ServletsFaq to solve this issue?
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse, have 2 TomCats installed 5 and 7. Classpath environment variables are follows:
Tomcar 5 installed in Program file and 7 in own directory guess that should not be any issues.
Created Sample HelloWorld example with folder struture and its working fine..Also imports doesn't work.

CLASSPATH=.;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;.;D:\owner\Java Progs\apache-tomcat-7.0.12\lib\servlet-api.jar;.;C:\Program Files\Java\jdk1.7.0\bin;
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also deleted the "work" directory under tomcat restarted the server but doesn't shows. The logs are not much help though.
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
type Status report

message /Beer1/BeerSelect.do

description The requested resource (/Beer1/BeerSelect.do) is not available.
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml to be under WEB-INF folder along with classes folder.
Working on sample MVC model import getting error "java.lang.NoClassDefFoundError: BeerExpert"
Thanks for no help!!!
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your actual question? Not able to run the servlet or the NoClassDefFoundError ?
For the former, check your url-pattern in web.xml and the URL you are tying in the browser.
For the latter, it simply means that your class is not in the correct folder.
 
shabana sheikh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resolved all the issues, web.xml to be beneath WEB-INF folder not web-apps folder along with WEB-INF.
Also classes compilations to be from root folder.
thks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic