Question

I need to grab a dynamically-named variable off of the request. This works in scriptlet form, but I'd rather not clutter up the page with scriptlets.

<%
    String requestValueKey = "something_" + request.getParameter("State") + "_" + request.getParameter("UUID");    
    String requestValue = request.getParameter(requestValueKey);
%>

I'd like to switch it to JSTL but I can't figure out how to come up with a dynamically named session value key that relies on other values in the session.

Was it helpful?

Solution

Use <c:set> to prepare the dynamic key and use brace notation [] to get a value by a dynamic key.

<c:set var="requestValueKey" value="something_${param.State}_${param.UUID}" />

Then you can get it by ${param[requestValueKey]} in remnant of the page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top