3

我知道 Struts 2 使用param拦截器自动将请求参数映射到操作类字段。但是,如果我想将参数映射到具有不同名称的操作字段怎么办。假设我有

<input type="text" name="username">

如果我想将此映射到以下字段

private String realName;
public String getRealName() {
return realName;
}

public void setRealName(String realName) {
      this.realNaame = realName;
}

我该如何做这个映射。我可以用吗

realName = request.getParameter("username");

如果是这样,我如何在操作类中获取请求对象?它也可以在带有 OGNL 表达式的 JSP 页面中工作usernamerealName?struts2 配置中还有其他方法可以进行这种映射吗?

4

1 回答 1

4

使用别名拦截器,简而言之:

<action name="someAction" class="com.examples.SomeAction">
    <!-- The value for the foo parameter will be applied as if it were named bar -->
    <param name="aliases">#{ 'foo' : 'bar' }</param>

    <interceptor-ref name="alias"/>
    <interceptor-ref name="defaultStack"/>
    <result>result.jsp</result>
</action>
于 2013-09-14T13:51:04.300 回答