Struts2 用ModelDriven接收参数
程序员文章站
2022-06-23 16:31:13
1、struts.xml
1、struts.xml
<struts> <constant name="struts.devmode" value="false"> <constant name="struts.enable.dynamicmethodinvocation" value="true"> <constant name="struts.i18n.encoding" value="utf-8"></constant> <package name="user" extends="struts-default"> <action name="user" class="com.wxh.action.useraction"> <result>/useraddsuccess.jsp</result> </action> </package> </constant></constant></struts>2、useraction.java
package com.wxh.action; import com.wxh.model.user; import com.opensymphony.xwork2.actionsupport; import com.opensymphony.xwork2.modeldriven; public class useraction extends actionsupport implements modeldriven{ private static final long serialversionuid = 1l; private user user=new user(); public string add(){ system.out.println("name="+user.getname()); system.out.println("age="+user.getage()); return success; } public user getmodel(){ return user; } }
3、user.java
package com.wxh.model; public class user { private string name; private int age; public string getname() { return name; } public void setname(string name) { this.name = name; } public int getage() { return age; } public void setage(int age) { this.age = age; } }4、index.jsp
添加用户
上一篇: Redmi K30 Pro艺术联名保护壳发布:49元出街神器
下一篇: 马来西亚沙巴亚庇旅游攻略
推荐阅读