Intellij idea Configure the simplest Web project for the MAVEN-STRUTS2 environment

Source: Internet
Author: User

Build a MAVEN project in idea

Look at the online big god hair of various blogs, and then build up a simple MAVEN-STRTUS2 project for beginners to learn

    1. New Project

The next step is to choose nothing, direct finish

2. Thejar package management in idea is implemented through Pom.xml, and the following is the configuration of the Pom.xml file to add the Struts2 jar package to the project

    1. Many people will be confused about the dependency configuration in Pom.xml, and recommend a website with various jar dependency configurations http://maven.oschina.net/index.html#nexus-search;quick~struts

3. Save the dependent copy to Pom.xml, and idea will automatically download the jar file to the Coorey of your locally installed MAVEN configuration (Jstl package is also added here)

4. start the server that configures the project, add Web support, etc.

After you add a server on, add Web support

5. Next Configure Web.xml,struts.xml, add the action package, and the action class, I'll just paste the code

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"/>

<!--setting up 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.

User:yang

Date:14-3-27

Time: 5:16

To change this template use File | Settings | File Templates.

--%>

<%@ page contenttype= "Text/html;charset=utf-8" language= "java"%>

<title></title>

<body>

This is a JSP page.

<br> ${hello}

</body>


The following is the directory tree for the project:

6. Configure the Tomcat server below

There is no need to configure Tomcat to configure a Tomcat, the configuration method will not be sent, directly publish the project bar

OK, so the project will be configured to the corresponding server, now only need to start the server wait on it


7. enter Http://localhost:8080/maven-struts/hello!hello in the browser

The results of the visit have been accomplished

Intellij idea to configure the simplest Web project for MAVEN-STRUTS2 environment

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.