如何从一个Servlet的传递数组到另一个servlet? [英] How to Pass Array from One Servlet to Another Servlet?
问题描述
我想从一个servlet的传递多个值到另一个的servlet。请告诉我如何传递?
I want to pass multiple values from one servlet to another one servlet. Please tell me how to pass that?
推荐答案
根据您使用会话:
- 店铺使用session.setAttribute()在会话变量数组;
- 检索使用session.getAttribute()数组;
不过该变量将留到会话死了,你用别的东西覆盖它,或者你删除它。
However the variable will stay until the session dies, you overwrite it with something else, or you remove it.
如果你转寄一个servlet来另一个servlet,可以将其存储在请求变量:
If you forward one servlet to another servlet, you can store it in the request variable:
- 了request.setAttribute()
您可以在调用后使用request.getAttribute()转发后读
Which you can read after forwarding using request.getAttribute() after calling
调用RequestDispatcher.forward()
RequestDispatcher.forward()
请注意这一点,如果你正在做的,而不是一个servlet重定向向前不起作用。
Note this does not work if you're doing a redirect instead of a servlet forward.
这篇关于如何从一个Servlet的传递数组到另一个servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!