The struts2.3.8 configuration in myeclipse is absolutely easy to use (thanks to many blogs)

Source: Internet
Author: User

1. Create a web project. My structure is as follows:

2. This step is very important: introduce necessary jar packages. Many blogs give 7 jar packages. Ignore them! Not complete! The jar packages required by struts2 of version 2.3.8 are as follows: a total of 11!


To introduce these 11 jar packages, right-click the project and choose Properties> JAVA build path> libraries> Add external jar! (By the way, I strongly despise some blogs that only introduce 7 packages in version 2.3.8. How do you do this ?)

3. modify web. xml under WEB-INF/lib

Join

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

Note: The filter-class is different from the previous one.

4. Compile the action class

Package com. Action;

Import com. opensymphony. xwork2.actionsupport;

Public class indexaction
Extends actionsupport {

Private Static
Final long
Serialversionuid = 1l;

Private Static
Final string message =
"Struct is running ";

Private string message =
"";

@ Override

Public String execute ()
Throws exception {

Setmessage (Message );

Return
Success;

}

Public String getmessage (){

Return message;

}

Public void setmessage (string message ){

This. Message = message;

}

}

5. Compile the view JSP

<% @ Page
Language = "Java"
Import = "Java. util .*"
Pageencoding = "utf8" %>

<% @ Taglib
Prefix = "S"
Uri = "/Struts-tags"
%>

<! Doctype
HTML public
"-// W3C // dtd html 4.01 transitional // en">

<HTML>

<Head>

<Title> my JSP 'success. jsp 'starting page </title>

</Head>

<Body>

<H2> <s: Property
Value = "message"/> </H2> <br>

</Body>

</Html>

6. Compile struts. xml

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

<Package
Name = "default"
Extends = "struts-Default">

<Action
Name = "helloworld"
Class = "com. Action. indexaction">

<Result
Name = "success">/views/success. jsp </result>

</Action>

</Package>

</Struts>

Note: <action
In name = "helloworld", helloworld corresponds to the address entered in the browser, and class corresponds to the action class to be called. <Result
Name = "success"> string returned by the execute method of the action class. My JSP page is placed under the views folder in the project root directory. Put struts. XML in the src directory!

7. Deploy and compile

Enter http: // localhost: 8080/XXX/helloworld. Action in the browser

OK ~~ Output struct is running, and the table is successful.

If you have any questions, please leave a message

 

See: http://blog.csdn.net/oxuannishi/article/details/8538386

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.