Inject a value into a property by Struts.xml configuration _2015.01.04

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.