0

I'm trying to make a website for an application we designed, and I'm struggling to find a method to save a session-attribute. I have the following code:

<%
    for (int i=0;i< (Integer) session.getAttribute("aantalLijsten");i++){
        %>
        <a href="wishList.jsp"><%= session.getAttribute("wishList"+i) %></a>
        <%
    } 
%>

where the attributes have been set in a servlet. I want to make a list of links, but they all have to go to the same page. On that page, I will generate the right content, based on the attribute wishList, which is the name on which the user clicked. Can I save that attribute in some way? Something like an "action on click: setAttribute("currentList", getAttribute("wishList"+i))"?

Eva
  • 313
  • 1
  • 6
  • 17

1 Answers1

0

If I have understood your question correctly then Try this:

<%
    for (int i=0;i< (Integer) session.getAttribute("aantalLijsten");i++){
%>
    <a href="wishList.jsp?param1="session.getAttribute("wishList"+i)><%= session.getAttribute("wishList"+i) %></a>
<%
    } 
%>

and in servlet you can access it as

String param1 = request.getParameter("param1");

but I strongly recommend you to not use scriplets in your JSP, have a look at How to avoid Java Code in JSP-Files?

Community
  • 1
  • 1
Bhushan
  • 6,151
  • 13
  • 58
  • 91