struts1.x中ActionForm的作用

一:通常是用来取网页中html标签的值,概念性的东西就不说了。通常就是ActionForm中设置变量属性和相应得getset方法。之后再action中调用actionFrom得到页面的值。我们只需写好actionForm,struts1会自动把页面的相应值匹配上。比如:页面上有2个标签,我们需要在action中得到这个2个标签的值新建一个包,包名叫com,TestForm和TestAction都建在com包下test.html:

<form action="xx.do">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" value="提交" />
</form>


 

二:在struts-config.xml中的配置:

<struts-config>
 <form-beans>
      <form-bean name="newsForm" type="com.NewsForm" />
      </form-beans>
<action path="/TestAction" name="newsForm" type="com.TestAction">

</action>


三:TestForm.java:

String username;
String password;
public static setUsername(String username){
this.username=username;
}
public String getUsername(){
return username;
}
public setPassword(String password){
this.password=password;
}
public String getPassword(){
return password;
}

四:TestAction.java:

public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
TestForm tf=(TestForm)form;
tf.getPassword();
tf.getUsername();
}


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值