从带有EL的html表单获取servlet中的请求参数

从带有EL的html表单获取servlet中的请求参数

本文介绍了从带有EL的html表单获取servlet中的请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下EL/html标记的JSP:

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>

渲染我的jsp时,第一个<td>标记显示$ {key}的评估值.但是,在<input>标记中,未正确评估$ {key}.当我尝试从servlet(request.getParameter(StringKey))检索输入作为请求参数时,我得到的文字$key不带花括号.当我执行request.getParameter("$key")时,我得到了${resource.get(key)}在EL中求值的字符串的多个值.

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.

这是怎么回事?

编辑

控制器方法(使用spring)代码:

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

推荐答案

如果资源是地图,则使用request.setAttribute("resource", resource)

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>

这篇关于从带有EL的html表单获取servlet中的请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:08