且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JSP页面中使用request.setAttribute

更新时间:2023-01-16 17:05:36

没有。不幸的是,Request对象只有在页面加载完成后才可用 - 一旦完成,你将丢失其中的所有值,除非它们已被存储在某处。

No. Unfortunately the Request object is only available until the page finishes loading - once it's complete, you'll lose all values in it unless they've been stored somewhere.

如果你想要通过以下任何一个请求保留属性:

If you want to persist attributes through requests you need to either:


  1. 在表单中有一个隐藏的输入,例如&lt ; input type =hiddenname =myhiddenvaluevalue =<%= request.getParameter(value)%> /&GT; 。然后,它将作为请求参数在servlet中可用。

  2. 将它放入会话中(参见 request.getSession() - 在JSP中,这只是 session

  1. Have a hidden input in your form, such as <input type="hidden" name="myhiddenvalue" value="<%= request.getParameter("value") %>" />. This will then be available in the servlet as a request parameter.
  2. Put it in the session (see request.getSession() - in a JSP this is available as simply session)

我建议使用会话因为它更容易管理。

I recommend using the Session as it's easier to manage.