Intellij IDEA web project for configuring the simplest maven-struts2 Environment

Source: Internet
Author: User

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 below

    If 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

        

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.