This article environment:
1. Eclipse for Java EE developer Helios
2. Struts 2.3.1.1
3. Tomcat 7.0.6
Configuration Prerequisites: Configure Tomcat, this article omits the Configure Tomcat step
In fact, the MyEclipse and Eclipse for Java EE configuration process is similar, the only difference is:
Eclipse for Java EE creates Dynamic Web projec;
MyEclipse is creating a Web Project;
1. Create a dynamic Web Project
2. Click Next
3. See output folder for Build\classes, and the traditional web-inf\classes some differences, but the development does not need attention;
4. Configure Web.xml in Web-inf to add the STRUTS2 framework to the Web application; Configure Struts.xml in SRC (eclipse will compile by copying all other files in the SRC directory except the Java file into web-inf\classes) to import the Struts core class library into the Web-inf\lib;
5. Preparation of Web.xml
The purpose of this configuration is to incorporate the STRUTS2 framework into the Web application, where a filter is configured, from which you can learn that the filter's role is to accomplish something before the servlet executes, from the <url-pattern> Can be seen that arbitrary requests will enter the scope of the STRUTS2 framework;
<?xml version= "1.0" encoding= "GBK"?> <web-app xmlns:xsi=
"Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version= " 3.0 ">
<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>
</web-app>
6. Preparation of Struts.xml
<?xml version= "1.0" encoding= "GBK"?> <!
DOCTYPE struts public
"-//apache Software foundation//dtd struts Configuration 2.0//en"
"http:// Struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
</struts>
Write Hello world
1. Create a hello.jsp and content for Hello STRUTS2!!!
2. Configure Struts.xml
<struts>
<constant name= "Struts.devmode" value= "true" ></constant>
<package name= " Hellopackage "namespace="/"extends=" Struts-default ">
<action name=" Hello ">
<result>/ hello.jsp</result>
</action>
</package>
</struts>
3. Deploy and fill out the Http://localhost:8888/StrutsDemo01/Hello in the browser
Note: In future development, you must add the elements in the <struts>:
<constant name= "Struts.devmode" value= "true" ></constant>
Because this indicates that it is in the developer mode, it means to provide more prompt information when the error occurs;