Home > Java > javaTutorial > body text

Detailed explanation of examples of Struts2 configuration in java

Y2J
Release: 2017-05-17 09:27:05
Original
1175 people have browsed it

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>
Copy after login

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>
Copy after login

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;
}
}
Copy after login

6. Add in the tag in struts.xml:


<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="helloworld" class="default package.HelloWorldAction">
<result>/result.jsp</result>
</action>
</package>
</struts>
Copy after login

7. Create View (Create result.jsp in the WebRoot directory):


<body>
This is result.jsp!
</body>
Copy after login

8.DebugRun

【Related recommendations 】

1. Special recommendation: "php Programmer Toolbox" V0.1 version download

2. Java Free Video Tutorial

3. YMP Online Manual

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!