Eclipse Configuration struts2.x

Source: Internet
Author: User
Tags prepare

Asked my classmates now javaweb mainstream framework is what. He said the basic framework is ssh,struts2+spring+hibernate, popular is Ssm,springmvc+spring+mybatis, originally planned to learn Struts1 framework, so do not learn, first learn Struts2, The first is Eclipse configuration Struts2.

First, download Struts2

Download the Struts2 package from http://struts.apache.org/download.cgi#struts25101, here I choose the download of min

Second, import Struts2

After download, unzip all the files under Lib and copy them to the STRUTS2 project you have created.

Three, STRUT2 configuration

1. Create the Struts.xml file under SRC, configure the following in XML, the <! introduced in XML DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.5//en"
"Http://struts.apache.org/dtds/struts-2.5.dtd", this DTD is used to verify the XML content format, if the lack of nodes, will be in the DTD and things do not go, and thus error, here also note that the root node is <struts></struts>, I forgot to gargan the node when I configured it today.

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts    Public " -//apache software foundation//dtd Struts Configuration 2.5//en "    http://struts.apache.org/dtds/struts-2.5.dtd" ><struts>    <packageextends= "Struts-default" >            <default- Action-ref name= "Hello"/>            <action name= "Hello" >                <result>/hello.jsp</result>            </action>    </Package ></struts>

2. The web-inf/web.xml is configured as follows, here the filter and filter-mapping are one by one corresponding, with the respective filter-name corresponding, I began to configure the time to define two Filter:struts-execute, Struts-prepare but only defined a filter-mapping:struts-prepare, in fact, the two filter class can be together, Use the following Org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter class.

   <filter>        <filter-name>struts-prepare</filter-name>        <filter-class> org.apache.struts2.dispatcher.filter.strutsprepareandexecutefilter</filter-class>    </ filter>    <filter-mapping>        <filter-name>struts-prepare</filter-name>        < url-pattern>/*</url-pattern>    </filter-mapping>

3. Create a new hello.jsp file under Webcontext because the result of the action configured in the struts.xml above is/hello.jsp. If hello.jsp is placed under Web-inf, result should be/web-inf/hello.jsp.

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts    Public " -//apache software foundation//dtd Struts Configuration 2.5//en "    http://struts.apache.org/dtds/struts-2.5.dtd" ><struts>    <packageextends= "Struts-default" >            <default- Action-ref name= "Hello"/>            <action name= "Hello" >                <result>/WEB-INF/hello.jsp</result>            </action>    </Package ></struts>

Four, the operation

In the body of the hello.jsp file, enter a line

Here to thank the next my classmate is my college roommate Zhang Mong, so late also help solve the problem.

Eclipse Configuration struts2.x

Related Article

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.