0
我正在嘗試創建簡單的Web應用程序。 這裏是我的web.xml
stackoverflowerror嘗試訪問Web應用程序時
<servlet>
<servlet-name>basicServlet</servlet-name>
<servlet-class>com.pack.BasicServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>basicServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
這是我index.jsp
是位於webapp/WEB-INF/jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic web page</title>
</head>
<body>
<h2>Data provided by server:</h2>
<p>
<c:choose>
<c:when test="${ not empty message }">
<h3>${message}</h3>
</c:when>
<c:otherwise>
<h3>none</h3>
</c:otherwise>
</c:choose>
</p>
</body>
</html>
這是我servlet
public class BasicServlet extends HttpServlet {
private IBasicService basicService;
@Override
public void init() throws ServletException {
basicService = new BasicService();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setAttribute("message", basicService.provideMessage());
req.getRequestDispatcher("/jsp/index.jsp").forward(req, resp); // 23 line
}
}
我建了一個war
並在Tomcat中部署它。但是,當我嘗試訪問它,我得到很長的堆棧跟蹤
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.pack.BasicServlet.doGet(BasicServlet.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.pack.BasicServlet.doGet(BasicServlet.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.pack.BasicServlet.doGet(BasicServlet.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.pack.BasicServlet.doGet(BasicServlet.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.pack.BasicServlet.doGet(BasicServlet.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
...
與root cause
java.lang.StackOverflowError
com.pack.BasicServlet.doGet(BasicServlet.java:22)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
....
問題是什麼?我很久以前使用了servlets
,所以也許我忘了一些東西...