问题
I have a JSP with the following EL/html tags:
<c:forEach var="key" items="${resource.stringPropertyNames()}">
<tr>
<td>${key}</td>
<td><input type = "text" name = "${key}" value = "${resource.get(key)}"></td>
</tr>
</c:forEach>
When my jsp is rendered, the first <td>
tag shows the evaluated value of ${key}. In the <input>
tag however, the ${key} is not evaluated correctly. When I try to retrieve the input as request parameters from my servlet (request.getParameter(StringKey)
), I get the literal $key
without the braces. When I do request.getParameter("$key")
, I get multiple values for the Strings that ${resource.get(key)}
evaluate to in the EL.
What is going on?
EDIT
Controller method (using spring) code:
@RequestMapping(value = URI_PATH + "{fileName}", method = RequestMethod.GET)
public String getProperties(@PathVariable String fileName, ModelMap modelMap) {
Properties resource = ..//get properties file
modelMap.addAttribute("resource", resource);
return "configuration" // maps to my jsp;
}
回答1:
If resource is a Map, which is set using request.setAttribute("resource", resource)
<c:forEach var="entry" items="${resource}">
<tr>
<td>${entry.key}</td>
<td><input type = "text" name = "${entry.key}" value = "${entry.value}"></td>
</tr>
</c:forEach>
来源:https://stackoverflow.com/questions/13481155/getting-a-request-parameter-in-a-servlet-from-html-form-set-with-el