在TokenHelper中的setSessionToken时引发java.lang.IllegalStateException [英] java.lang.IllegalStateException thrown while setSessionToken in TokenHelper

查看:143
本文介绍了在TokenHelper中的setSessionToken时引发java.lang.IllegalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Jetty服务器的Linux操作系统上运行的Java应用程序.

I have a Java application running on Linux OS with Jetty server.

Struts操作,该操作会更改Linux系统的日期和时间以及在呈现另一个页面之后. 动作已成功执行,但是在呈现页面时它将引发java.lang.IllegalStateException.

Struts action which changes the date and time of Linux System and after it renders another page. An action is performed successfully but while rendering the page it will throw java.lang.IllegalStateException.

我在该JSP页面中使用了"s:token"来防止表单的两次提交.

I have used "s:token" in that JSP page for preventing double submissions of form.

错误跟踪如下

ERROR TokenHelper Error creating HttpSession due response is committed to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: null
 java.lang.IllegalStateException
    at org.eclipse.jetty.server.session.AbstractSession.checkValid(AbstractSession.java:109)
    at org.eclipse.jetty.server.session.HashedSession.checkValid(HashedSession.java:73)
    at org.eclipse.jetty.server.session.AbstractSession.getAttribute(AbstractSession.java:132)
    at org.apache.struts2.dispatcher.SessionMap.get(SessionMap.java:161)
    at org.apache.struts2.dispatcher.SessionMap.put(SessionMap.java:179)
    at org.apache.struts2.util.TokenHelper.setSessionToken(TokenHelper.java:93)
    at org.apache.struts2.util.TokenHelper.setToken(TokenHelper.java:79)
    at org.apache.struts2.components.Token.buildToken(Token.java:107)
    at org.apache.struts2.components.Token.evaluateExtraParams(Token.java:97)
    at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:886)
    at org.apache.struts2.components.UIBean.end(UIBean.java:535)
    at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    at org.apache.jsp.pages.Continue_jsp._jspx_meth_s_token_0(org.apache.jsp.pages.Continue_jsp:495)
    at org.apache.jsp.pages.Continue_jsp._jspx_meth_s_form_0(org.apache.jsp.pages.Continue_jsp:429)
    at org.apache.jsp.pages.Continue_jsp.access$6(org.apache.jsp.pages.Continue_jsp:407)
    at org.apache.jsp.pages.Continue_jsp$Continue_jspHelper.invoke2(org.apache.jsp.pages.Continue_jsp:1197)
    at org.apache.jsp.pages.Continue_jsp$Continue_jspHelper.invoke(org.apache.jsp.pages.Continue_jsp:1221)

请让我们知道可能的解决方案或建议,以解决该错误.

Please let us know possible solution or suggestions to handle the error.

推荐答案

错误TokenHelper创建HttpSession时出错,该错误已提交给客户端.您可以使用CreateSessionInterceptor或根据操作创建HttpSession,然后再将结果呈现给客户端.

ERROR TokenHelper Error creating HttpSession due response is committed to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client.

您可以使用类似的代码创建Http会话

You can create Http session with the code similar to

    ActionContext context = ActionContext.getContext();
    SessionMap<String, T> sessionMap = (SessionMap<String, T>) context.getSession();

    if (sessionMap == null) {
        sessionMap = new SessionMap<String, T>(ServletActionContext.getRequest());
        context.setSession((Map<String, Object>) sessionMap);
    }


createSession拦截器.


There's createSession interceptor.

如果HttpSession不存在,此拦截器将创建HttpSession,还将重新创建SessionMap并将其放入ServletActionContext.

This interceptor creates the HttpSession if it doesn't exist, also SessionMap is recreated and put in ServletActionContext.

当在freemarker中使用<@s.token>标记时,这特别有用 模板.该标记确实要求已创建HttpSession 因为freemarker会立即将响应提交给客户端.

This is particular useful when using the <@s.token> tag in freemarker templates. The tag do require that a HttpSession is already created since freemarker commits the response to the client immediately.

这篇关于在TokenHelper中的setSessionToken时引发java.lang.IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆