前进jsp中的问题 给出错误消息:
2016-01-27 13:22:13.192:WARN:oejs.ServletHandler:qtp1132700707-25: Error for /
java.lang.StackOverflowError
at java.lang.String.startsWith(String.java:1434)
at org.eclipse.jetty.server.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:352)
at org.eclipse.jetty.server.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:368)
at org.eclipse.jetty.server.Dispatcher$ForwardAttributes.setAttribute(Dispatcher.java:368)
at org.eclipse.jetty.server.Request.setAttribute(Request.java:1925)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:839)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:224)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:199)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:74)
at pages.index.doGet(index.java:18)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
的doGet:
@WebServlet(urlPatterns = "/")
public class index extends HttpServlet{
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
request.getRequestDispatcher("/index.jsp").forward(request,response);
}
}
启动服务器:
WebAppContext webapp1 = new WebAppContext();
webapp1.setResourceBase("src/Pages");
webapp1.setContextPath("/");
webapp1.setDefaultsDescriptor("src/WEB-INF/web.xml");
webapp1.setDescriptor("src/WEB-INF/web.xml");
server.setHandler(webapp1);
getServletContext()方法 没有帮助
请帮助我了解问题所在。
添加了index.jsp,生成了NetBeans 8.1,我没有改变。:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>JSP Page</title>
</head>
<body>
<h1><h:outputText value="Hello World!"/></h1>
</body>
</html>
</f:view>
答案 0 :(得分:0)
你的index.jsp
正在调用servlet的问题,而servlet正在调用index.jsp
,因此它们具有无限循环。更改页面servlet应转发
getServletContext().getRequestDispatcher("/page.jsp").forward(request,response);
答案 1 :(得分:0)
我确实做了
getServletContext().getRequestDispatcher("/page.jsp").forward(request,response);
正如Roman C.所建议的那样。但是并没有单独解决它。我还删除了所有servlet映射。