1: Download struts2.3.16.3 on the website, currently for the latest version. http://www.struts.apache.org/download.cgi
Download "Full Distribution" version
Unzip after download.
2.
Create a dynamic WEB project item with eclipse
One thing to note here is that the. class file of the src file that you created is put under web-inf/classes. So how do you put it? Follow such actions.
file-"New-" Dynamic Web Project-"Enter the project name (hellostruts) and click Next. Pay attention here, look at the picture.
Change the following build classes in the diagram to Webcontent/web-inf/classes
Click Finish
3.
Then add the necessary components extracted from the first step to the webcontent/web-inf/lib of the project.
How do we choose to face these 108 components? Sometimes choosing more is not necessarily good; Here I only select the necessary 9 jar files
The entire engineering structure, the road strength to be consistent:
4. The next step is to write a JSP page
index.jsp
1 <%@ Page Language="Java"ContentType="text/html; charset=iso-8859-1"2 pageencoding="iso-8859-1"%>3 <%@ taglib Prefix="s"URI="/struts-tags"%>4 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">5 <HTML>6 <Head>7 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">8 <title>Insert Title here</title>9 </Head>Ten <Body> One <s:aAction= "Hello">Hello</s:a> A </Body> - </HTML>
success.jsp
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><%@ taglib Prefix="s"URI="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body> <S:propertyvalue= "Hello"/></Body></HTML>
Xml
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" 3 xmlns= "Http://java.sun.com/xml/ns/javaee" 4 Xmlns:web= "Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 5 xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee6 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd " 7 ID= "webapp_id"version= "3.0">8 <Filter>9 <Filter-name>Struts2</Filter-name>Ten <Filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</Filter-class> One </Filter> A - <filter-mapping> - <Filter-name>Struts2</Filter-name> the <Url-pattern>/*</Url-pattern> - </filter-mapping> - <welcome-file-list> - <!--Index page - + <Welcome-file>index.jsp</Welcome-file> - </welcome-file-list> + </Web-app>
Next, create a struts.xml file in the SRC directory
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE Struts public3 "-//apache software foundation//dtd Struts Configuration 2.0//en"4 "Http://struts.apache.org/dtds/struts-2.0.dtd">5 <Struts>6 < Packagename= "Default"namespace="/"extends= "Struts-default">7 <Actionname= "Hello"class= "Com.action.TestAction">8 <result>/success.jsp</result>9 </Action>Ten </ Package> One </Struts>
Struts.properties
< Struts . Il8n.encoding value = "UTF-8" />
Next, create a package under the SRC directory, and then under this package, new class;
Testaction.java
1 Packagecom.action;2 ImportCom.opensymphony.xwork2.ActionSupport;3 4 Public classTestactionextendsActionsupport {5 Private Static Final Longserialversionuid=1l;6 PrivateString Hello;7 PublicString Gethello () {8 returnHello;9 }Ten Public voidSethello (String hello) { One This. hello=Hello; A } - PublicString Execute ()throwsexception{ -hello= "Hello World"; the returnSUCCESS; - } -}
5. Run, right-click Project Name---run as---run on server
struts2.3 Creating a Project