Configuring the STRUTS2 development environment

Source: Internet
Author: User

Configuring the STRUTS2 development environment

Interview questions:

Struts2 is not on the basis of Struts1, is based on the development of WEBWORK2. Although the difference between the Struts2 and struts names is not very large, it is almost different in code writing style.

Build STRUTS2 Development environment:

1. Required JAR Package

2. Writing the configuration file

3. Add the STRUTS2 MVC Framework launch configuration in Web. xml

Required JAR Packages:

STRUTS2 case

The necessary preparation

STRUTS2 's development environment.

First step: Introduce the JAR file

Step Two: Create the STRUTS2 configuration file as follows

<?xmlversion= "1.0" encoding= "UTF-8"?>

<! DOCTYPE Struts Public

"-//apache software foundation//dtdstruts Configuration 2.3//en"

"Http://struts.apache.org/dtds/struts-2.3.dtd" >

<struts>

</struts>

Step Three: Add the filter filter that the boot struts2 relies on to add the Web. xml file

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

First step: Configure the XML file

Configuration file for STRUTS2 application:

Struts2 The default configuration file is Struts.xml, which is stored under Web-inf/classes, and the configuration template for the file is:

<?xml version= "1.0" encoding= "UTF-8"?>

<! DOCTYPE Struts Public

"-//apache software foundation//dtd Struts configuration2.0//en"

"Http://struts.apache.org/dtds/struts-2.0.dtd" >

<struts>

<package name= "test" extends= "Struts-default" namespace= "/cs" >

<action name= "Hello" class= "cn.csdn.hr.action.HelloAction" >

<result name= "Login" type= "dispatcher"; /index.jsp</result>

</action>

</package>

</struts>

Step Two: Create an action

Package cn.csdn.hr.action;

Public class helloaction {

/* Method first must return string String */

Public String Execute () {

SYSTEM.OUT.PRINTLN ("-----Action Execution-----");

return "Login";

}

}

Step Three: Analysis

Http://localhost:8080/day11/cs/hello.action

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.