各位大侠:请问ActionForm在struts1中有什么用途?多谢~~~
1个回答
展开全部
通常是用来取网页中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();
}
新建一个包,包名叫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();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询