会话在表单提交时过期

问题描述:

在某些情况下,我有一个窗体,该窗体从我的应用程序显示为针对各种事件动态弹出的窗体.我正在填写表格并提交,导致会话过期.

There is a scenario in which I am having a form which is shown from my application as a pop up dynamically for various events. I am filling up the form and submitting it which causes session expiry.

我发现,当在表单中打印请求标头的值时,我发现jsession id丢失了,或者有时创建了新的jseesion id.

I found out that when printing the values of the request headers in the form, i see that the jsession id is missing or sometimes new jseesion id is created.

这不是经常发生.在工作情况下,我不会丢失任何jsession ID或得到不同的jseesion ID.

This is not happening frequently. In working cases I am not missing any jsession id or getting differnt jseesion id's.

有什么建议吗?

下面是代码示例.

<HTML>
 <HEAD>
  </HEAD>
   <%
  Enumeration<String> headerNames = request.getHeaderNames(); 
 while (headerNames.hasMoreElements())
 { 
    String headerName = headerNames.nextElement();
  String headerValue = request.getHeader(headerName);
   System.out.println("Header Name   " +headerName );
  System.out.println("headerValue   " +headerValue );
 } 
 %>
 <body>
 Comments </br>
<form name = 'savefrm' action ='save.jsp'>
<textarea name = 'comments' id = 'text' cols=38 rows=8>"+comments.trim()+"</textarea>
<input type="submit" value="ok"/>
</form>
 </body>
 </html>

在web.xml文件中:

On web.xml file :

<web-app>
    <session-config>
        <session-timeout>20</session-timeout>
   </session-config>
</web-app>

20 = 20分钟

或者您可以在代码内完成该操作:

Or you can do it inside the code :

HttpSession session = request.getSession();
session.setMaxInactiveInterval(20*60);

20 * 60 = 20分钟

20 * 60 = 20 minutes