如何从一个Servlet的传递数组到另一个servlet?

如何从一个Servlet的传递数组到另一个servlet?

问题描述:

我想从一个servlet的传递多个值到另一个的servlet。请告诉我如何传递?

I want to pass multiple values from one servlet to another one servlet. Please tell me how to pass that?

根据您使用会话:


  1. 店铺使用session.setAttribute()在会话变量数组;

  2. 检索使用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:


  1. 了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.