在JSP页面中使用request.setAttribute [英] Using request.setAttribute in a JSP page

查看:607
本文介绍了在JSP页面中使用request.setAttribute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在JSP页面上使用 request.setAttribute 然后在HTML Submit中获取 Servlet中的相同请求属性

Is it possible to use request.setAttribute on a JSP page and then on HTML Submit get the same request attribute in the Servlet?

推荐答案

没有。不幸的是,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. 在表单中有一个隐藏的输入,例如< ; input type =hiddenname =myhiddenvaluevalue =<%= request.getParameter(value)%> /> 。然后,它将作为请求参数在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.

这篇关于在JSP页面中使用request.setAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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