Configuring the STRUTS2 development environment
Interview questions:
Struts2 is not on the basis of Struts1, is based on the development of WEBWORK2. Although the difference between the Struts2 and struts names is not very large, it is almost different in code writing style.
Build STRUTS2 Development environment:
1. Required JAR Package
2. Writing the configuration file
3. Add the STRUTS2 MVC Framework launch configuration in Web. xml
Required JAR Packages:
STRUTS2 case
The necessary preparation
STRUTS2 's development environment.
First step: Introduce the JAR file
Step Two: Create the STRUTS2 configuration file as follows
<?xmlversion= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtdstruts Configuration 2.3//en"
"Http://struts.apache.org/dtds/struts-2.3.dtd" >
<struts>
</struts>
Step Three: Add the filter filter that the boot struts2 relies on to add the Web. xml file
<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>
First step: Configure the XML file
Configuration file for STRUTS2 application:
Struts2 The default configuration file is Struts.xml, which is stored under Web-inf/classes, and the configuration template for the file is:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts configuration2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>
<package name= "test" extends= "Struts-default" namespace= "/cs" >
<action name= "Hello" class= "cn.csdn.hr.action.HelloAction" >
<result name= "Login" type= "dispatcher"; /index.jsp</result>
</action>
</package>
</struts>
Step Two: Create an action
Package cn.csdn.hr.action;
Public class helloaction {
/* Method first must return string String */
Public String Execute () {
SYSTEM.OUT.PRINTLN ("-----Action Execution-----");
return "Login";
}
}
Step Three: Analysis
Http://localhost:8080/day11/cs/hello.action