亚马逊欧洲站入口网址,制造业erp系统软件有哪些,如何利用网站赚钱,深圳多区最新通知Struts2中Action接收参数的方法主要有以下三种#xff1a;1.使用Action的属性接收参数#xff1a; a.定义#xff1a;在Action类中定义属性#xff0c;创建get和set方法#xff1b; b.接收#xff1a;通过属性接收参数#xff0c;如#xff1a;userName#xff… Struts2中Action接收参数的方法主要有以下三种1.使用Action的属性接收参数 a.定义在Action类中定义属性创建get和set方法 b.接收通过属性接收参数如userName c.发送使用属性名传递参数如user1!add?userNameMagci2.使用DomainModel接收参数 a.定义定义Model类在Action中定义Model类的对象不需要new创建该对象的get和set方法 b.接收通过对象的属性接收参数如user.getUserName() c.发送使用对象的属性传递参数如user2!add?user.userNameMGC3.使用ModelDriven接收参数 a.定义Action实现ModelDriven泛型接口定义Model类的对象必须new通过getModel方法返回该对象 b.接收通过对象的属性接收参数如user.getUserName() c.发送直接使用属性名传递参数如user2!add?userNameMGC实例web.xml:Java代码 ?xml version1.0 encodingUTF-8? web-app version2.5 xmlnshttp://java.sun.com/xml/ns/javaee xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd welcome-file-list welcome-filehello.jsp/welcome-file /welcome-file-list filter filter-namestruts2/filter-name filter-classorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter/filter-class /filter filter-mapping filter-namestruts2/filter-name url-pattern/*/url-pattern /filter-mapping /web-app [java]view plaincopy?xml version1.0 encodingUTF-8? web-app version2.5 xmlnshttp://java.sun.com/xml/ns/javaee xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd welcome-file-list welcome-filehello.jsp/welcome-file /welcome-file-list filter filter-namestruts2/filter-name filter-classorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter/filter-class /filter filter-mapping filter-namestruts2/filter-name url-pattern/*/url-pattern /filter-mapping /web-app struts.xml:写道?xml version1.0 encodingUTF-8 ?!DOCTYPE struts PUBLIC-//Apache Software Foundation//DTD Struts Configuration 2.0//ENhttp://struts.apache.org/dtds/struts-2.0.dtdstruts!-- constant namestruts.enable.DynamicMethodInvocation valuefalse /constant namestruts.devMode valuefalse /include fileexample.xml/package namedefault namespace/ extendsstruts-defaultdefault-action-ref nameindex /action nameindexresult typeredirectActionparam nameactionNameHelloWorld/paramparam namenamespace/example/param/result/action/package--!-- Add packages here --constant namestruts.devMode valuetrue /package nameuser namespace/ extendsstruts-defaultaction nameuser* classcn.edu.ahau.mgc.struts2.action.UserAction{1}result/addSuccess.jsp/result/action/package/strutsUser.java:Java代码 package cn.edu.ahau.mgc.struts2.mode; publicclass User { private String userName; private String password; public String getUserName() { returnthis.userName; } publicvoid setUserName(String userName) { this.userName userName; } public String getPassword() { returnthis.password; } publicvoid setPassword(String password) { this.password password; } } [java]view plaincopypackage cn.edu.ahau.mgc.struts2.mode; publicclass User { private String userName; private String password; public String getUserName() { returnthis.userName; } publicvoid setUserName(String userName) { this.userName userName; } public String getPassword() { returnthis.password; } publicvoid setPassword(String password) { this.password password; } } UserAction1.java:写道package cn.edu.ahau.mgc.struts2.action;import com.opensymphony.xwork2.ActionSupport;public class UserAction1 extends ActionSupport {private String userName;private String password;public String add() {System.out.println(userName: userName);System.out.println(password: password);return SUCCESS;}public String getUserName() {return this.userName;}public void setUserName(String userName) {this.userName userName;}public String getPassword() {return this.password;}public void setPassword(String password) {this.password password;}}UserAction2.java:写道package cn.edu.ahau.mgc.struts2.action;import com.opensymphony.xwork2.ActionSupport;import cn.edu.ahau.mgc.struts2.mode.User;public class UserAction2 extends ActionSupport {private User user;public String add() {System.out.println(userName: user.getUserName());System.out.println(password: user.getPassword());return SUCCESS;}public User getUser() {return this.user;}public void setUser(User user) {this.user user;}}UserAction3.java:写道package cn.edu.ahau.mgc.struts2.action;import cn.edu.ahau.mgc.struts2.mode.User;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public class UserAction3 extends ActionSupport implements ModelDrivenUser {private User user new User();public String add() {System.out.println(userName: user.getUserName());System.out.print(password: user.getPassword());return SUCCESS;}public User getModel() {return this.user;}}index.jsp:写道% page languagejava importjava.util.* pageEncodingGB18030%%String path request.getContextPath();String basePath request.getScheme()://request.getServerName():request.getServerPort()path/;%!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhtmlheadbase href%basePath%titleParam/titlemeta http-equivpragma contentno-cachemeta http-equivcache-control contentno-cachemeta http-equivexpires content0 meta http-equivkeywords contentkeyword1,keyword2,keyword3meta http-equivdescription contentThis is my page!--link relstylesheet typetext/css hrefstyles.css--/headbodya hrefuser1!add?userNameMagcipassword123456user1!add?userNameMagcipassword123456/abr /br /a hrefuser2!add?user.userNameMGCuser.passwordabcuser2!add?user.userNameMGCuser.passwordabc/abr /br /a hrefuser3!add?userNameMaGCpassword000000user3!add?userNameMaGCpassword000000/a/body/html addSuccess.jsp:Java代码 % page languagejavaimportjava.util.* pageEncodingGB18030% % String path request.getContextPath(); String basePath request.getScheme()://request.getServerName():request.getServerPort()path/; % !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN html head base href%basePath% titleAddSuccess/title meta http-equivpragma contentno-cache meta http-equivcache-control contentno-cache meta http-equivexpires content0 meta http-equivkeywords contentkeyword1,keyword2,keyword3 meta http-equivdescription contentThis is my page !-- link relstylesheet typetext/css hrefstyles.css -- /head body User Add Success! br /body /html 转载于:https://blog.51cto.com/lebron/1373552