Webwork使用ParamertersInterceptor和StaticParamertersInterceptor

本文介绍了一种通过表单字段名映射到Action类中getter/setter方法的技术,并展示了如何使用StaticParametersInterceptor从配置文件中读取参数并映射到Action类属性。通过一个具体的例子,包括JSP页面、Action类代码及配置文件,演示了整个过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ParamertersInterceptor可以根据表单字段名,映射到action中相应属性的getter/setter方法

 StaticParamertersInterceptor可以讲xwork.xml中为action配置参数,映射到映射到action中相应属性的getter/setter方法

 

JSP:

 

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding
="GB18030"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="webwork" prefix="ww" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<ww:form action="interceptor.dhtml" method="post">
  
<ww:textfield label="user" name="age"/>
  
<ww:submit value="submit"/>
</ww:form>
</body>
</html>


Action:

 

package ch5.example1;

import com.opensymphony.xwork.ActionSupport;

public class Interceptor extends ActionSupport {
   
private String age;
   
private String firstname;
   
private String lastname;
public String getFirstname() {
    
return firstname;
}


public void setFirstname(String firstname) {
    
this.firstname = firstname;
}


public String getLastname() {
    
return lastname;
}


public void setLastname(String lastname) {
    
this.lastname = lastname;
}


@Override
public String execute() throws Exception {
    System.out.println(age);
    System.out.println(firstname);
    System.out.println(lastname);
    
return NONE;
}


public String getAge() {
    
return age;
}


public void setAge(String age) {
    
this.age = age;
}

   
}


配置文件:

 

 <action name="interceptor" class="ch5.example1.Interceptor"> 
      
<param name="firstname">Gao</param>
      
<param name="lastname">Xiang</param>
  
</action>

运行结果(jsp文件文本框输入25.提交):
25
Gao
Xiang
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值