我想显示一个网页[索引页面],其中包含 3 个选项来选择汽车。可以通过单选按钮或文本框选择汽车。
选择特定的汽车时,Servlet应响应显示用户选择的客户端。此外,servlet 应该计算所选汽车的价格。但现在,我不谈价格,只是在浏览器上显示用户的选择。
我收到错误类型状态报告消息 /carShop/tish.com.CarServlet2 描述 请求的资源 (/carShop/tish.com.CarServlet2) 不可用。可能出了什么问题:-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE> Welcome to CarShop </TITLE>
</HEAD>
<BODY>
<FORM Action = "tish.com.CarServlet2" METHOD=POST>
<BR>Select a Type of Car:<BR>
Brand <INPUT TYPE=text NAME="Brand" > <br>
Year <INPUT TYPE=text NAME="Year" > <br>
<input type="checkbox" name="car" value="honda">Honda<br>
<input type="checkbox" name="car" value="nissan">Nissan<br>
<INPUT TYPE= SUBMIT NAME= "Submit " Value = "Submit the Selection">
<br>
<INPUT TYPE= RESET NAME = "RESET" Value = "Reset">
</FORM>
</BODY>
</HTML>
小服务程序:-
package tish.com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CarServlet2 extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("Testing my Car Sevlet");
//System.out.println(arg0.getInitParameter("Year"));
//config =arg0;
String [] car = req.getParameterValues("car");
PrintWriter writer = resp.getWriter();
resp.setContentType("text/html");
writer.print("<html> <body>");
writer.print("<hl> Your choice is </hl>");
for (String s: car)
{
writer.print("<l1>" + s+ "/l1>");
}
writer.print("</body></html> ");
}
}
网页.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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>Welcome.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>CarServlet2</servlet-name>
<url-pattern>/CarServlet2</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>CarServlet2</servlet-name>
<servlet-class>tish.com.CarServlet2</servlet-class>
</servlet>
</web-app>
文件目录设置:
carShop/tish/com.CarServlet2
请帮助我理解我做错了什么?
谢谢