01:web.xml configuration:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.4"xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "><!--01: Start Struts2 Frame--<filter> <filter-name>struts2</filter-name> <filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pat Tern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</we Lcome-file> </welcome-file-list></web-app>
02: Writing The Action class
Packagecom.self.action;/*** 02: Write the corresponding processing method*/ Public classhelloworldaction {PrivateString message; PublicString Dohelloworld () {return"Doresult"; } //To inject a value into a property, you need to provide a set method Public voidsetmessage (String message) { This. Message =message; } //Show values on page, need get method PublicString getMessage () {returnmessage; }}
03: Configure Struts.xml
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public " -//apache software foundation//dtd Struts Configuration 2.0//en " http://struts.apache.org/dtds/struts-2.0.dtd" ><struts> <!--O3: Configure the appropriate classes, methods- -< packageextends= "Struts-default" > Class= "Com.self.action.HelloWorldAction" method= "Dohelloworld" > <!--inject values-- <param name= "message" >in_message</param> <result name= " Doresult "> /showresult.jsp </result> </action> </Package ></struts>
04: Page Get Value:
<!--4th step: Display <body><BR><br><BR> <center> Place page on Web- INF, so the user directly does not have access to the <BR><br> Action property injection value: ${message }<br></ Center> </body>
Inject a value into a property by Struts.xml configuration _2015.01.04