Getting a request parameter in a servlet from html form set with EL

谁说胖子不能爱 提交于 2019-12-08 11:13:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!