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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top