简体   繁体   English

Servlet示例-找不到文件

[英]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. 我使用tomcat 6在Eclipse中制作了一个servlet应用程序。我将一些信息从表单发送到servlet。 I get the error - Firefox can't find the file at /C:/workspace-jee/Beer-v1/WebContent/html/SelectBeer.do. 我收到错误消息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 - 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 - 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. Servlet BeerSelect实际上存在并且具有正确的代码。

Tomcat startup logs - I guess they call this catalina or something. 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

EDIT - My project structure inside eclipse jee: 编辑-我在Eclipse JEE中的项目结构:

在此处输入图片说明

You have 2 ways to work around this problem: 您有两种方法来解决此问题:
option 1. Change the action to read as below: 选项1.将操作更改为如下:

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

Option 2. Change web.xml as below: 选项2。更改web.xml,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM