在tomcat 7中运行并使用IntelliJ Idea 12创建的servlet中调用doGet方法两次 [英] doGet method is called twice in a servlet running in tomcat 7 and created with IntelliJ Idea 12

查看:324
本文介绍了在tomcat 7中运行并使用IntelliJ Idea 12创建的servlet中调用doGet方法两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a simple servlet with only one System.out.println() method in doGet body, but when I am running it inside Tomcat 7 using IntelliJ Idea 12 I get the message that System.out.println() method prints twice.

这是我的web.xml:

This is my 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>

这是SimpleServlet.java:

This is 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.");
    }
}

这是SimpleServletProject.iml:

This is 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>

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

..and this is an image of Tomcat 7 settings :

推荐答案

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

I've changed the url mapping to / and now I have both my simple jsp page running at http://localhost:8080/SimpleServerProject and my servlet running the doGet method just once!

这篇关于在tomcat 7中运行并使用IntelliJ Idea 12创建的servlet中调用doGet方法两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆