I want to know a method how can I send 1 specified item for JSTL’s foreach to other JSP or servlet, to print detailed info about that item.
Giving followin code:
<c:forEach var="note" items="${notes}">
<tr>
<td>${note.getTitle()}</td>
<td>${note.getRealDate()}</td>
<td>${note.getUserDate()}</td>
<td>
<form action="showdetails.jsp">
<input type="submit" value="show details" name="details" />
</form>
</td>
</tr>
</c:forEach>
I need to replace my form, or remake it, to get something that does the job, and I’m out of ideas…
ah, btw. Note has method shown above + showDetails() with String return. And I want to display them all, or just do String all = note.toString(); in jsp/servlet
Just pass an identifier as request parameter and change the URL to be a servlet one. If you insist to use a submit button, pass the identifier as a hidden input field:
In the servlet which is mapped on an URL pattern of
/showdetailsjust do the following job indoGet()method:In the
showdetails.jspyou can then use${note}to access the selectedNote.Exactly the above servlet is also useable when you use a link instead as Bozho suggests, with only one little difference, in the servlet you’re able to preprocess the request (to find and prepare the right
Noteobject for display).See also: