Build a maven project in idea
Look at the various blog, and then build a simple maven-strtus2 project for beginners to learn
Copy the dependency to pom. xml and save it. idea will automatically download the jar file to the maven configuration library installed locally (add the jstl package here)
Start configuring the target server, adding web support, etc.
After adding the server, add web Support
Next, configure web. xml, struts. xml, and add the action package and action class. I will paste the Code directly.Web. xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
Struts. xml
<? 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> <! -- Supports dynamic calling --> <constant name = "struts. enable. DynamicMethodInvocation" value = "true"/> <! -- Set the development mode --> <constant name = "struts. devMode "value =" true "/> <package name =" front "namespace ="/"extends =" struts-default "> <action name =" user "class =" hello. helloAction "> <result name =" success ">/index. jsp </result> </action> </package> </struts>
HelloAction. java
package hello;import com.opensymphony.xwork2.ActionSupport;import org.apache.struts2.ServletActionContext;import javax.servlet.http.HttpServletRequest;/** * Created by Yang on 14-3-27. */public class HelloAction extends ActionSupport{ HttpServletRequest request = ServletActionContext.getRequest(); public String hello() { request.setAttribute("hello", "hello world!"); return SUCCESS; }}Index. jsp
<% -- Created by IntelliJ IDEA. user: Yang Date: 14-3-27 Time: PM To change this template use File | Settings | File Templates. -- %> <% @ page contentType = "text/html; charset = UTF-8 "language =" java "%> The following is the Project location:
Configure the tomcat server belowIf tomcat is not configured, You need to configure a tomcat first. The configuration method will not be released. Release the project directly.OK, so that the project is configured to the corresponding server. Now you only need to start the server and wait.
Enter http: // localhost: 8080/maven-struts/hello in the browser! Hello
Access results are complete