0

I am making a web page that displays large sets of data. Initially, the user enters a form in a jsp that includes them uploading a file, and checking boxes for options. When the user hits submit, it goes to a servlet that processes the form information. The information is processed and as a result, several large arrays of Strings are created. I then redirect to the display page, passing the parameters as follows:

request.setAttribute("blah", array);
request.getRequestDispatcher(page).forward(request,response);

On the display page I want to be able to give the user the option to choose which page he/she wants to view. To do this, I made links on the top of the page that passed the page number as a parameter:

<a href="DisplayPage?Page=x">Page x</a>

(DisplayPage is the servlet displaying the data, so the link points to itself with a different parameter)

The problem is, in order to display the data again, the large arrays must be passed back to DisplayPage. How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Robogeeko
  • 53
  • 1
  • 8

1 Answers1

1

Either pass them as multi-value request parameter in the link as well,

<a href="DisplayPage?Page=x&blah=value1&blah=value2&blah=value3">Page x</a>
String[] blah = request.getParameterValues("blah");

or store it in the session, if necessary identified by an unique ID which you also pass as request parameter.

String id = UUID.randomUUID().toString();
request.getSession().setAttribute(id, array);
request.setAttribute("id", id);
<a href="DisplayPage?Page=x&blah=${id}">Page x</a>
Object blah = request.getSession().getAttribute(request.getParameter("blah"));
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for the response! I'll try it out I've never heard of storing something in the session – Robogeeko Jul 18 '12 at 17:17
  • You're welcome. To learn more about sessions, you may find this answer helpful: http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading/3106909#3106909 – BalusC Jul 18 '12 at 17:30
  • 1
    You're welcome. Be careful that you don't store *too much* data in the session. Use where possible `session.removeAttribute()` to remove it when you're ready with it. – BalusC Jul 18 '12 at 17:34