[英]Google App Engine Java servlet read JSP
I am trying to have our servlets on Google App Engine Java, read the result of a JSP using the method here: Pass data from Java Servlet to JSP? 我试图在Google App Engine Java上使用我们的servlet,请使用以下方法读取JSP的结果:将数据从Java Servlet传递到JSP?
Specifically our code is 具体来说,我们的代码是
ByteArrayOutputStream bufferStream = new ByteArrayOutputStream();
ResponseWrapper responseWrapper = new ResponseWrapper(response, bufferStream);
getServletContext().getRequestDispatcher(jspUrl).forward(request, responseWrapper);**
responseWrapper.flushBuffer();
return bufferStream.toString();
However since we have sessions turned off in appengine-web.xml 但是,由于我们在appengine-web.xml中关闭了会话
<sessions-enabled>false</sessions-enabled>
we get the error below. 我们得到下面的错误。 Is there anyway for a servlet to read a JSP without GAE trying to add a session?
无论如何,servlet无需GAE尝试添加会话即可读取JSP?
com.google.apphosting.vmruntime.VmApiProxyDelegate convertApiResponseRpcErrorToException: Security violation: invalid request id used!
W 2014-10-16 12:16:19.004
org.gails.util.server.TLogUtil logException: IndexServlet.readJspPage() /index.html
java.lang.RuntimeException: Session support is not enabled in appengine-web.xml. To enable sessions, put <sessions-enabled>true</sessions-enabled> in that file. Without it, getSession() is allowed, but manipulation of sessionattributes is not. Session support is not enabled in appengine-web.xml. To enable sessions, put <sessions-enabled>true</sessions-enabled> in that file. Without it, getSession() is allowed, but manipulation of sessionattributes is not.
java.lang.RuntimeException: Session support is not enabled in appengine-web.xml. To enable sessions, put <sessions-enabled>true</sessions-enabled> in that file. Without it, getSession() is allowed, but manipulation of sessionattributes is not.
at com.google.apphosting.utils.jetty9.StubSessionManager$StubSession.throwException(StubSessionManager.java:86)
at com.google.apphosting.utils.jetty9.StubSessionManager$StubSession.setAttribute(StubSessionManager.java:74)
at org.eclipse.jetty.security.SecurityHandler$1.sessionCreated(SecurityHandler.java:335)
at org.eclipse.jetty.server.session.AbstractSessionManager.addSession(AbstractSessionManager.java:686)
at org.eclipse.jetty.server.session.AbstractSessionManager.newHttpSession(AbstractSessionManager.java:566)
at org.eclipse.jetty.server.Request.getSession(Request.java:1406)
at org.eclipse.jetty.server.Request.getSession(Request.java:1379)
at org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:134)
at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:109)
at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:60)
at org.apache.jsp._005ftradeos_jsp._jspService(_005ftradeos_jsp.java:100)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.eclipse.jetty.servlet.JspPropertyGroupServlet.service(JspPropertyGroupServlet.java:130)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at com.google.apphosting.vmruntime.jetty9.VmRuntimeWebAppContext.doScope(VmRuntimeWebAppContext.java:366)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:191)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:72)
at org.gails.site.server.IndexServlet.readJspPage(IndexServlet.java:279)
If you check the stack trace, the RequestDispatcher
forward is triggering code that requires the use of sessions. 如果检查堆栈跟踪,则前进的
RequestDispatcher
会触发需要使用会话的代码。 The error message clearly tells you that you need to have <sessions-enabled>true</sessions-enabled>
. 该错误消息清楚地告诉您,您需要具有
<sessions-enabled>true</sessions-enabled>
。 The origin of this may be the fact that you get the RequestDispatcher from a call to getServletContext()
, which if you check the javadoc, requires a session. 这可能是由于您从对
getServletContext()
的调用中获取RequestDispatcher的事实,如果您检查javadoc,则需要进行会话。
There may be other ways to get a RequestDispatcher
to forward to a JSP, that don't create a session. 可能有其他方法可以使
RequestDispatcher
转发到JSP,而不创建会话。 Try to get the RequestDispatcher
from the HttpServletRequest
object with req.getRequestDispatcher()
. 尝试使用
req.getRequestDispatcher()
从HttpServletRequest
对象获取RequestDispatcher
。
Either enable sessions, or at the very least, if the above advice didn't help and you still don't want to use sessions, you could try to use RequestDispatcher.include()
, which might not require sessions(?), although again you would have to test. 启用会话,或者至少,如果以上建议没有帮助并且您仍然不想使用会话,则可以尝试使用
RequestDispatcher.include()
),尽管可能不需要session(?)再次,您将不得不测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.