我使用tomcat 6在Eclipse中创建了一个servlet应用程序。我将一些信息从表单发送到servlet。我收到错误 - Firefox can't find the file at /C:/workspace-jee/Beer-v1/WebContent/html/SelectBeer.do.
如何解决此问题?相关信息如下。如果您需要更多信息,请告诉我。
HTML页面
<!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
实际存在且代码正确。
Tomcat启动日志 - 我猜他们称之为catalina
或其他什么。
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
编辑 - 我在eclipse中的项目结构:
答案 0 :(得分:1)
您有两种方法可以解决此问题:
选项1.将操作更改为如下所示:
<form method = "POST" action="/Beer-v1/SelectBeer.do">
选项2.更改web.xml,如下所示:
<url-pattern>/html/SelectBeer.do</url-pattern>