简体   繁体   English

如何重用httpservlet请求

[英]How to reuse the httpservlet request

Hi is there anyway to make a request persistent? 您好,无论如何,您可以将请求持久化? In my web application I need to check what Check-box has the user ticked, i get this value by using Request.getPart("Convert File"); 在我的Web应用程序中,我需要检查用户勾选了哪个复选框,我可以通过使用Request.getPart(“ Convert File”)获得此值。 After this I need to upload the file the user selects but when I parse the request I get a null value because the request has already been used. 此后,我需要上传用户选择的文件,但是当我解析请求时,我会得到一个空值,因为该请求已被使用。 Is there any way around this issue? 有什么办法解决这个问题? Like saving the request? 喜欢保存请求吗? Any help would be appreciated. 任何帮助,将不胜感激。

If you need the information in the request for future use, you have to store the information in a wider scope, for example in the session. 如果您在请求中需要信息以备将来使用,则必须将信息存储在更大的范围内,例如在会话中。

//Storing value
Session session = request.getSession();
session.setAttribute("key", "value");

//Retrieve value
session.getAttribute("key")

Use httpSession. 使用httpSession。 You can use api like: 您可以像这样使用api:

HttpSession session = httpServletRequest.getSession(false);
session.setAttribute("Key", "Value");

And later on when user revisits, you could check same attribute like: 之后,当用户再次访问时,您可以检查相同的属性,例如:

session.getAttribute("Key");

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

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