I'm looping through a list of items, and I'd like to get a request parameter based on the item's index. I could easily do it with a scriptlet as done below, but I'd like to use expression language.
<c:forEach var="item" items="${list}" varStatus="count">
<!-- This would work -->
<%=request.getParameter("item_" + count.index)%>
<!-- I'd like to make this work -->
${param.?????}
</c:forEach>
In short, to get Request Parameters in a JSP page you should: Create a jsp page that begins with the <%code fragment%> scriptlet. It can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.
getParameter is a function name in JSP which is used to retrieve data from an HTML/JSP page and passed into the JSP page. The function is designated as getParameter() function. This is a client-side data retrieval process. The full function can be written as request.
Using getParameter or getParameterMap is the more general solution.
A request-scope object is stored in the implicit request object. The request scope ends at the conclusion of the HTTP request. scope="session" : The object is accessible from any JSP page that is sharing the same HTTP session as the JSP page that created the object.
<c:set var="index" value="item_${count.index}" />
${param[index]}
Unfortunately, + doesn't work for strings like in plain Java, so
${param["index_" + count.index]}
doesn't work ;-(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With