[STRUTS2 Study notes] section II using MAVEN to manage and construct a Struts 2 Web application seven steps

Source: Internet
Author: User
Tags log log

This address: http://blog.csdn.net/sushengmiyan/article/details/40303897

Official Document: http://struts.apache.org/release/2.3.x/docs/ Create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html

This article Sushengmiyan

--------------------------------------------------------------------------------------------------------------- ---------------------


Learning Maven Basics can take the MAVEN learning Note: http://blog.csdn.net/sushengmiyan/article/details/40142771


The first step is to create a Java WEB program

Create a working directory and use MAVEN to execute the following command:

MVN archetype:generate-dgroupid=com.susheng.struts2maven-dartifactid=hellostruts-darchetypeartifactid= Maven-archetype-quickstart-dinteractivemode=false
This command creates a simple Maven project, and you can see the project catalog that generated the MAVEN format, followed by a pom.xml file.

Modify this file to add the following node content:

<build>    <finalName>basic_struts</finalName></build>


This section corresponds to the official tutorial:


Step Two: Increase index,jsp

Next, we add a simple index.jsp page to this program. Under the Src/main/webapp folder, create a index.jsp titled "Welcome to Struts 2 's most basic program" and add a H1 content to the body: "Welcome to Struts 2!"

The contents are as follows:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Execute the MVN clean package to build a war file to copy this file into your Web container, such as Tomcat. I have constructed a Basic_struts.war file here, and I placed it under Tomcat's WebApp directory, and I started Tomcat to enter the address in the browser: http://localhost:8080/basic_struts/index.jsp

The display page is as follows:


So far, we've just created a simple program using MAVEN, and we didn't include struts in it.


This section corresponds to the official tutorial:



Step three: Add struts 2 to our project

Add the following in the Pom.xml:

    <dependency>      <groupId>org.apache.struts</groupId>      <artifactId>struts2-core< /artifactid>      <version>2.3.16.3</version>  </dependency>
By adding this, you can see that the jar packages introduced by Maven include STRUTS2 and xwork as well as the Javaassis jar package, which explains how the code works.

This section corresponds to the official tutorial:



Fourth Step add log log

Under the Src\main folder, create a new resources folder with the Log4j.xml configuration file, which reads as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE log4j:configuration Public "-//log4j/log4j configuration//en" "Log4j.dtd" > <log4j:configuration xmlns: log4j= "http://jakarta.apache.org/log4j/" > <appender name= "STDOUT" class= "Org.apache.log4j.ConsoleAppender" &       Gt  <layout class= "Org.apache.log4j.PatternLayout" > <param name= "Conversionpattern" value= "%d%-5p%c.%m:%l -%m%n "/> </layout> </appender> <!--Specify the logging level for loggers from other L Ibraries--<logger name= "Com.opensymphony" > <level value= "DEBUG"/> </logger> < Logger name= "Org.apache.struts2" > <level value= "DEBUG"/> </logger> <!--for all other L Oggers log only info and above log messages-<root> <priority value= "info"/> <appe  Nder-ref ref= "STDOUT"/> </root> </log4j:configuration>

This section corresponds to the official tutorial:



Fifth step: Add the Struts 2 filter to our application

Modify the Web. xml file to add the following:

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


This section corresponds to the official tutorial:


Sixth step, add the struts2 configuration file

In the resources folder just now, add Struts.xml file, the contents are as follows:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts public    "-//apache software foundation//dtd struts Configuration 2.0//en"    "/http Struts.apache.org/dtds/struts-2.0.dtd "> <struts>     <constant name=" Struts.devmode "value=" true "/ >     <package name= "basicstruts2" extends= "Struts-default" >         <action name= "index" >            < result>/index.jsp</result>        </action>     </package> </struts>

This section corresponds to the official tutorial:



Seventh step: Construct a Deployment application

Build the war package using Maven's Clean Packages command, and I'm building a Basic_ Struts.war, copy this file to Tomcat's WebApp directory, start the Tomcat server, watch the command line display, then launch the browser, enter http://localhost:8080/basic_struts/ Index.action View Web page content as follows:



This section corresponds to the official tutorial:


So far, the first example has been shown.




[STRUTS2 Study notes] section II using MAVEN to manage and construct a Struts 2 Web application seven steps

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.