简体   繁体   English

Jetty Servlet转发JSP:转发错误

[英]Jetty Servlet forward jsp: forward error

The problem in the forward jsp Gives an error message: 正向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);
    }
}

Start Server: 启动服务器:

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() does not help getServletContext()没有帮助

Please help me understand what the problem is. 请帮助我了解问题所在。

Added index.jsp, generate NetBeans 8.1, i not change.: 添加了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>

The problem that your index.jsp is calling servlet, and servlet is calling index.jsp so they have infinite loop. 您的index.jsp正在调用servlet,而servlet正在调用index.jsp使它们具有无限循环。 Change the page servlet should forward 更改页面servlet应该转发

getServletContext().getRequestDispatcher("/page.jsp").forward(request,response);

I did do the 我确实做了

getServletContext().getRequestDispatcher("/page.jsp").forward(request,response);

as suggested by Roman C. However that didn't solve it alone. 正如罗曼·C(Roman C)所建议的。但是,这并不能单独解决。 I also removed all servlet mappings. 我还删除了所有servlet映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM