01: Guide Package Configuration Web. xml
<?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/J2EEhttp//java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "><!-- on: 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><!--01: Change. Action access to. Do--><constant name=" Struts.action.extension "value=" do ></constant><!--02: Specify the default encoding, Equivalent to HttpServletRequest's Setcharacterencoding method, also used for freemarker, velocity output--><constant name= " Struts.i18n.encoding "value=" UTF-8 "></constant><include file=" Department.xml "/><include file=" Employ.xml "/></struts>
04: Writing Department.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><package name=" dep "namespace="/department "extends=" Struts-default "><action name=" HelloWorld "class=" com.self.action.HelloWorldAction "method=" Dohelloworld " ><param name= "message" >department</param><result name= "Doresult" >/showresult.jsp</result ></action></package></struts>
05: Writing Employ.xml
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts public "-//apache software foundation//dtd struts Configuration 2.0//en" namespace= "employ " extends=" Struts-default "><action name=" HelloWorld "class=" Com.self.action.HelloWorldAction "method=" Dohelloworld "><param name=" message ">employ</param><result name=" Doresult ">/showresult.jsp </result></action></package></struts>
06: Writing the page
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
07: Access Path 1
Show Results 1:employ
08: Access Path 2
Show Results 2:department
Multiple profile Security Module partitioning