How to Pass Array from One Servlet to Another Servlet?

后端 未结 3 1302
花落未央
花落未央 2021-01-23 01:33

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

3条回答
  •  难免孤独
    2021-01-23 01:36

    Depending if you use sessions:

    1. Store the array in the session variable using session.setAttribute();
    2. Retrieve the array using session.getAttribute();

    However the variable will stay until the session dies, you overwrite it with something else, or you remove it.

    If you forward one servlet to another servlet, you can store it in the request variable:

    1. request.setAttribute()

    Which you can read after forwarding using request.getAttribute() after calling

    RequestDispatcher.forward()

    Note this does not work if you're doing a redirect instead of a servlet forward.

提交回复
热议问题