在tomcat 7中运行并使用IntelliJ Idea 12创建的servlet中调用doGet方法两次

ski*_*box 5 java tomcat servlets intellij-idea java-ee

我在doGet体中创建了一个只有一个System.out.println()方法的简单servlet,但是当我使用IntelliJ Idea 12在Tomcat 7中运行它时,我收到System.out.println()方法打印两次的消息.

这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">

    <servlet>
        <description>A simple servlet</description>
        <display-name>SimpleServlet</display-name>
        <servlet-name>SimpleServlet</servlet-name>
        <servlet-class>org.skiabox.myservlet.SimpleServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>SimpleServlet</servlet-name>
        <url-pattern>/SimpleServletPath</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

这是SimpleServlet.java:

package org.skiabox.myservlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SimpleServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Hello from GET method.");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是SimpleServletProject.iml:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <descriptors>
          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
        </descriptors>
        <webroots>
          <root url="file://$MODULE_DIR$/web" relative="/SimpleServletProject" />
        </webroots>
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" scope="PROVIDED" name="Tomcat 7.0" level="application_server_libraries" />
  </component>
</module>
Run Code Online (Sandbox Code Playgroud)

..这是Tomcat 7设置的图像:

Tomcat设置

ski*_*box 2

我已将 url 映射更改为 /,现在我的简单 jsp 页面正在运行,http://localhost:8080/SimpleServerProject而我的 servlet 只运行一次 doGet 方法!