This article mainly introduces the configuration and simple cases of java Struts2. Friends who need it can refer to the configuration and simple cases of
Struts2:
1. Create a dynamic web project (let it automatically generate the web.xml file when creating)
2. Introduce relevant jar packages
3. Configure in web.xml
(The first file loaded after starting the tomcat server is web.xml)
Add in the configuration Filter:
<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>
4. Create the core file of struts (struts.xml) and create it in the Java Resources-src file directory. The content is:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> </struts>
5. Also create an Action class in the Java Resources-src file directory, inherit from ActionSupport , and override the execute method in the parent class:
public class HelloWorldAction extends ActionSupport { @Override public String execute() throws Exception { System.out.println("执行Action"); return SUCCESS; } }
6. Add in the
<struts> <package name="default" namespace="/" extends="struts-default"> <action name="helloworld" class="default package.HelloWorldAction"> <result>/result.jsp</result> </action> </package> </struts>
7. Create View (Create result.jsp in the WebRoot directory):
<body> This is result.jsp! </body>
8.DebugRun
【Related recommendations 】
1. Special recommendation: "php Programmer Toolbox" V0.1 version download
The above is the detailed content of Detailed explanation of examples of Struts2 configuration in java. For more information, please follow other related articles on the PHP Chinese website!