<form action="../SelectBeer.do" method="POST">
<p>Select Beer Characteristics</p>
<p>Color</p>
<select name="color" size="1">
<option>light</option>
<option>amber</option>
<option>brown</option>
<option>dark</option>
</select>
<br><br>
<center>
<input type="submit">
</center>
</form>
以下是我的form.html的代码,其路径是/Library/Tomcat/webapps/Project/form.html
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
@WebServlet("/SelectBeer.do")
class BeerSelect extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse reponse) throws ServletException,IOException
{
reponse.setContentType("text/html");
PrintWriter out=reponse.getWriter();
out.println("Beer Selection Advice<br>");
String c=request.getParameter("color");
out.println("<br>Got Beer Color "+ c);
}
}
这是我的BeerSelect.java文件,其路径为/Users/MyName/Desktop/ServletProjects/BeerAdvisor/src/com/example/web/BeerSelect.java
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
当我提交表单时,页面显示Error404 Not Found,原始服务器没有找到目标资源的当前表示,或者不愿意透露存在该表示。可以请某人帮忙。