简体   繁体   English

Java 中 request.setAttribute 有什么用?

[英]What is the use of request.setAttribute in Java?

I can understand that it's like assigning a value to a key.我可以理解这就像为一个键分配一个值。 For ex: request.setAttribute("listedit", people);例如: request.setAttribute("listedit", people);

where people is a string.人是一个字符串。 How it will assign people to "listedit" and where/how the key should be used?它将如何将人们分配到“listedit”以及应该在哪里/如何使用密钥?

It's just an attribute Map .它只是一个属性Map Most commonly your view (JSP or other) will access the values by key, so you can write something like Hello ${name} in your view, and the value bound to the key "name" will then be displayed.大多数情况下,您的视图(JSP 或其他)将通过键访问值,因此您可以在视图中编写类似Hello ${name} ,然后将显示绑定到键“name”的值。

request.setAttribute only make the key available in the following jsp page. request.setAttribute 仅使密钥在以下 jsp 页面中可用。

For example, the flow like page1->page2, if we use request.setAttribute in page1, then only page2 can get the key value set in page2.比如page1->page2这样的流程,如果我们在page1中使用request.setAttribute,那么只有page2才能拿到page2中设置的key值。

request.setAttribute(): 1.May help you in getting rid of the hidden fields. request.setAttribute(): 1.可以帮助您摆脱隐藏字段。 2.Use it most of times when you just need the attribute just for the consecutive page. 2.当你只需要连续页面的属性时,大多数时候使用它。

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

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