在Eclipse中更改web.xml <servlet-mapping>没有任何效果(Eclipse Juno,Tomcat 6)

mmm*_*mmm 1 eclipse jsp tomcat servlets

我是Web编程的新手,我正在尝试编写一个简单的应用程序来从输入表单中收集数据并将其传递给servlet HTTPServletRequest.我知道每个servlet都需要映射到里面的特定URL 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" 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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>InputFormTest</display-name>
  <welcome-file-list>
    <welcome-file>InputForm.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>InputFormTest</display-name>
    <servlet-name>InputFormTest</servlet-name>
    <servlet-class>com.jsp.core.InputFormTest</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>InputFormTest</servlet-name>
    <url-pattern>/InputFormTest</url-pattern>
  </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

InputForm.jsp正确显示.我使用Eclipse的上下文菜单添加了InputFormTest servlet,即New - > Servlet,它具有以下代码:

package jsp.core;

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;

/**
 * Servlet implementation class InputFormTest
 */
public class InputFormTest extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>InputFormTest</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>User inserted: " + request.getParameter("id") + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}
Run Code Online (Sandbox Code Playgroud)

我有两个问题:

  1. 首先,在Eclipse中运行应用程序后,我收到以下错误

    HTTP状态404 - /InputFormTest


    类型状态报告

    message/InputFormTest

    description请求的资源不可用.


    Apache Tomcat/6.0.36

  2. 其次,改变<url-pattern>/InputFormTest</url-pattern>web.xml不影响上面的输出,这是奇怪的,因为我认为message /InputFormTest应该反映内设置web.xml

任何提示赞赏.

mmm*_*mmm 5

好的,我终于明白了.作为一个可以猜测,答案很简单:Eclipse的内部浏览器缓存的网页.

这意味着,该页面被显示在Eclipse内部浏览器中运行使用"运行方式 - >在服务器上运行"此次变更项目后是一个古老的,缓存的页面.之后需要手动刷新.在Web开发项目中出现奇怪的行为.除此之外,一切都很好 - 案件关闭.