Transferred from: http://blog.csdn.net/oxuannishi/article/details/8538386
1. To build a Web project project, my structure is as follows:
2. This step is important: by introducing the necessary jar packages, many blogs give 7 jar packages, which are not complete at all! The jar package required for version 2.3.8 Struts2 is as follows: Total 11!
The introduction method is: Right-click Project->properties->java build Path->libraries->add external jar to bring these 11 jar packages into! (By the way, I strongly despise that some blogs only introduce 7 packages under the 2.3.8 version, how do you do that?) )
3. Modify the Web. XML under Web-inf/lib
Join
<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-pattern>/*</url-pattern>
</filter-mapping>
Note: The filter-class is different from the previous
4. Write the Action class
Package com.action;
Import Com.opensymphony.xwork2.ActionSupport;
public class Indexaction extends actionsupport{
Private static final long serialversionuid = 1L;
private static final String MESSAGE = "struct is running";
Private String message = "";
@Override
Public String Execute () throws Exception {
Setmessage (MESSAGE);
return SUCCESS;
}
Public String GetMessage () {
return message;
}
public void Setmessage (String message) {
this.message = message;
}
}
5. Write the JSP for the view
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF8"%>
<%@ taglib prefix= "s" uri= "/struts-tags"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title>my JSP ' success.jsp ' starting page</title>
<body>
</body>
6. Writing 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>
<package name= "Default" extends= "Struts-default" >
<action name= "HelloWorld" class= "Com.action.IndexAction" >
<result name= "Success" >/views/success.jsp</result>
</action>
</package>
</struts>
Note: The HelloWorld in <action name= "HelloWorld" corresponds to the address entered on the browser, and the class corresponds to the action class to be invoked. <result name= "Success" > the string that corresponds to the Execute method of the action class. My JSP page is placed under the Views folder in the project root directory. This struts.xml is placed in the SRC directory!
7. Deployment compilation
Enter http://localhost:8080/xxx/HelloWorld.action on the browser
ok~~ output struct is running success for table success there's a picture of the truth.
struts2.3.8 configuration guaranteed to be absolutely usable under myeclipse