jsp - How can I get the content from a session variable? -


My status:

On my jsp site, I show a table when someone clicks on a line , Then this row should be marked for example with the color of the other badte color. More than one row can be marked. Two things are important first: I have to remember which rows are marked second: in which order.

I think:

I have an ArrayList and have entered all the row IDs in it. Therefore, I will solve both problems. Now I have the next click and line ID (req.getSession (.) SetAttribute (req.getParameter ("rowID"), "+ + arrayList.size ());) in the session for the jsp file

My problem is in the JSP file:

Now I do not know which session variable is named.

If this line ID is changed in Clicked? ..

I have just received the bean name. How do I get content from this session, if this exact line is marked?

Normally I am setting a session variable: req.getSession.setAttribut ("printView", boolean.true) and get the session variable so:

I work with Straps, Formin and JSP.

Sorry, I am not English and this problem is so difficult for me, so I can not declare it better at this time.

First analyze what you are storing in the session:

  req.getSession (). SetAttribute (req.getParameter ("rowID"), "+ + simplist. Size ());  

req.getParameter ("rowID") returns the string value of the request parameter. If your page links to yourPage.jsp? RowID = 3 , then its value will be "3" . HttpSession # setAttribute (string, object)

This value will be used as the key in the "+ + arrayList.size () < / Strong> is just a string representation of the size of your simple list in which you are trying to store the ID of the clicked rows

Answer your question "I Now what not called the session variable name. "Because this rowID is not worth the value of the request parameter The Rbr is not, therefore, can not be given.

If you are in the session, then you want to check that it repeats only through its properties:

 For  (count elem: req.getSession (). GetAttributeNames ()) {string name = elem.nextElement (); System.out.println (name + ":" + req.getSession (.) GetAttribute (name)); }  

If you do not store your array list in the session, the previous code will probably return something like this:

  1: 0 5: 0 1: 0  

As Vinegar suggested that I do the following:

  string clicked ROIID = req.getParameter ("rowID"); & Lt; String & gt; Arraylist = (list) req.getSession (). GetAttribute ("clickedRows"); If (! ArrayList.contains (clickedRowId)) {arrayList.add (clickedRowId); } Req.getSession (). SetAttribute ("clickedRows", array list);  

Your array list will keep a list of the clicked row IDs and their index will tell you about your chronological order.

Note: Definitely better and more scalable ways to achieve it anyway, implementing your solution and then for a better one is a good idea.


Comments