My problem is that I create an ArrayList in the servlet class filled by a form inside an html page. Then I pass my array-list to a jsp page that prints all the objects. Now every object i printed becomes a "href" that calls the "doGet" method of the servlet. I need to pass the index of the object selected by clicking on the link.
//This is the implementation of the method doGet of my servlet:
//I know that is wrong to use getAttribute but I don't know what else could really work.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
**String ciao = request.getAttribute("id");** //this is the error
int k = Integer.parseInt(ciao); // this is because i pass a String object and i'm already sure that it will be a number.
String invio = lista.get(k);
request.setAttribute("key", invio);
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/views/es3-item.jsp");
dispatcher.forward(request, response);
}
This is my jsp (es3-list.jsp) page that prints the objects:
<c:forEach var="valore" items="${requestScope.message}" varStatus="theCount">//message is the key to pass the ArrayList "lista" to this jsp page.
<a href ="./es3"> <c:out value="${valore}"/> </a>
<a id="${theCount.index}"></a>
</c:forEach>