我遇到了一个奇怪的问题。对于单个HTTP请求,我的servlet的doGet方法被多次调用。重新运行每10-12秒发生一次,直到初始过程完成。
以下是我的servlet代码
private static final long serialVersionUID = WebServiceServlet.class.getCanonicalName().hashCode();
private ServletContext servletContext;
/**
* @see HttpServlet#HttpServlet()
*/
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
servletContext = servletConfig.getServletContext();
}
/*public WebServiceServlet() {
super();
}*/
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String output = null;
/*
* Calling the Operation Manager which will decide the operation type
* and call the corresponding operation binder and set the return
* response generated in http response.
*/
// Request Processing
response.setContentType("application/json; charset=UTF-8");
PrintWriter out = response.getWriter();
out.print(output);
out.close();
}
@Override
public void destroy() {
super.destroy();
}
下面是web.xml中的映射
<servlet>
<description></description>
<display-name>WebServiceServlet</display-name>
<servlet-name>WebServiceServlet</servlet-name>
<servlet-class>com.servlet.WebServiceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WebServiceServlet</servlet-name>
<url-pattern>/web.do</url-pattern>
</servlet-mapping>
我正在使用SEAM和JSF,但这是一个独立的servlet。日志中没有例外。我还验证了INIT方法只被调用一次。这是正在重复的服务方法。所有重新运行的身份哈希码都是相同的(System.identityHashCode(this))。
调用是从REST API测试程序进行的。呼叫者没有多次呼叫。重播发生在tomcat容器上。
我在我的智慧结束。还有其他人遇到过这个问题吗?
答案 0 :(得分:0)
我也遇到过同样的问题。
只需将@post
方法保留在servlet类中。如果有,请注释掉@get
和@put
。
谢谢