Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dynamically access request parameters with JSP EL?

Tags:

java

jsp

jstl

el

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>
like image 415
ScArcher2 Avatar asked Jan 19 '09 18:01

ScArcher2


People also ask

How can we get request parameters in jsp?

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.

How parameters can be accessed from HTML using JSP?

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.

Which method of JSP is useful to access the query string?

Using getParameter or getParameterMap is the more general solution.

What is Requestscope in JSP?

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.


1 Answers

<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 ;-(

like image 196
Peter Štibraný Avatar answered Oct 24 '22 18:10

Peter Štibraný