Erran Morad
Erran Morad

Reputation: 4743

Servlet example - File not found

I made a servlet app in Eclipse with tomcat 6. I send some info from a form to a servlet. I get the error - Firefox can't find the file at /C:/workspace-jee/Beer-v1/WebContent/html/SelectBeer.do. How do I fix this problem ? Related info is given below. Please tell me if you need more info.

HTML page -

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1 align="center">Beer Selection Page</h1>
<form method = "POST" action="SelectBeer.do">

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>
<center>
<input type = "SUBMIT">
</center>
</form>

</body>
</html>

Web.xml -

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Beer-v1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>BeerSelect</display-name>
    <servlet-name>BeerSelect</servlet-name>
    <servlet-class>com.example.web.BeerSelect</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>BeerSelect</servlet-name>
    <url-pattern>/SelectBeer.do</url-pattern>
  </servlet-mapping>
</web-app>

Servlet BeerSelect actually exists and has correct code.

Tomcat startup logs - I guess they call this catalina or something.

Apr 27, 2014 10:00:00 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: 
C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;....more paths here.
Apr 27, 2014 10:00:00 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Apr 27, 2014 10:00:00 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 878 ms
Apr 27, 2014 10:00:00 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 27, 2014 10:00:00 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.39
Apr 27, 2014 10:00:00 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Apr 27, 2014 10:00:00 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 27, 2014 10:00:00 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/32  config=null
Apr 27, 2014 10:00:00 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 532 ms

EDIT - My project structure inside eclipse jee:

enter image description here

Upvotes: 1

Views: 2086

Answers (1)

AdityaKeyal
AdityaKeyal

Reputation: 1228

You have 2 ways to work around this problem:
option 1. Change the action to read as below:

<form method = "POST" action="/Beer-v1/SelectBeer.do">

Option 2. Change web.xml as below:

<url-pattern>/html/SelectBeer.do</url-pattern>

Upvotes: 1

Related Questions