0

I developed a small web app using tomcat 7 and javac compiler, i compiled my servlet successfuly and deployed the class file correctly. My html form runs however when i click the submit button on the html it is suppose to run the servlet which then print some advice on the page but this error is produced:

HTTP Status 404 - HTTP Status 404 - /beer-v1/%E2%80%9DSelectBeer.do%E2%80%9D


type Status report

message /beer-v1/%E2%80%9DSelectBeer.do%E2%80%9D

description The requested resource is not available.


Apache Tomcat/7.0.34


type Status report

message /beer-v1/SelectBeer.do

description The requested resource is not available.


Apache Tomcat/7.0.34

Here is my html code:

    <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" value="ok" />

        </center>

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

and my deployment descriptor:

<servlet>

    <servlet-name>Ch3 Beer</servlet-name>

    <servlet-class>com.example.web.BeerSelect</servlet-class>

</servlet>

<servlet-mapping>

    <servlet-name>Ch3 Beer</servlet-name>

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

</servlet-mapping>

last my servlet:

package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet {

public void doPost(HttpServletRequest request,

        HttpServletResponse response)

        throws IOException, ServletException {

    response.setContentType("text/html");

    PrintWriter out = response.getWriter();

    out.println("Beer Selection Advice<br>");

    String c = request.getParameter("color");

    out.println("<br>Got beer color " + c);
 }
}

im using Java 6 javac compiler Help me out please.

2 Answers2

1

Don't forget to declare explicitly the appropiate charset on your html file, at head section.

<head><meta charset="utf-8"> <title>... </head>

%E2%80%9D represents hex notation of right double quotation character (using UTF-8). So, it seems that Tomcat is trying to convert ”SelectBeer.do”`to UTF-8 finding no encoding declaration.

Hope it helps.

Val Martinez
  • 617
  • 6
  • 15
0

write action in form as below and test again

action=”/SelectBeer.do”

sujikin
  • 351
  • 3
  • 11