Struts development < configuring struts in eclipse. A >

Source: Internet
Author: User

1. Get the Struts jar package

1.1 First download the struts package here at (select Struts-

1.2 Unzip to get the following folder

Some official examples of struts are under the Apps folder

Docs has long been the official API documentation

LIB package is struts all the jar packages

SRC is a resource file for some examples

Note: Next we need to get the jar package we need, instead of all the jar files in the Lib directory, if all imports are likely to conflict

So what are the jar packs we need?

1.3 Open Apps folder, unzip Struts2-blank.war to get sample files

1.4 Opening the jar package inside the web-inf/lib is the jar package required for our basic struts operation. Take them out and stay with them.

2. Support for struts in the project

2.1 Open Eclipse New Dynamic web

2.2 Copy the first step of the jar package to the project Web-inf/lib directory

2.3 Adding Web. XML to the project and configuring

Add the Web. xml file and configure the Struts filter in the Web-inf root directory

<span Style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "UTF-8"? ><web-app id= "Webapp_9" version= "2.4" xmlns= " Xml/ns/j2ee "xmlns:xsi=" "xsi:schemalocation=" NS/J2EE "> <display-name>struts blank</display-name > <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping&    Gt <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list></web -app></span> 

3. Build struts and achieve

3.1 New action inheritance Actionsupport in SCR

<span style= "FONT-SIZE:18PX;" >package Fzl.struts.demo;import Com.opensymphony.xwork2.actionsupport;public class UserAction extends Actionsupport {@Overridepublic String execute () throws Exception {System.out.println ("--------useraction-------"); Return "Success";}} </span>

3.2 Configuring the Struts.xml file

Create a Struts.xml file and configure it in the SRC root directory

<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.3//en" " Struts-2.3.dtd "><struts> <package name=" Default "namespace="/"extends=" Struts-default "><action Name= "Hello" class= "fzl.struts.demo.UserAction" ><result>/hello.jsp</result></action>    </package></struts></span>

4 Creating a display layer file

Build hello.jsp under the Web-inf folder

<span style= "FONT-SIZE:18PX;" ><%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://" >

Start Tomcat, enter http://localhost: Port number/strutsdemo/hello in the address bar to get the following page

Here our struts configuration has been completed and implemented.

Finally, summarize

Basic steps:

1. Copy struts jar into project (these jar packages can be found in the blank project in apps)
2. Add struts2 filter to Web. xml
3. Configure STRUTS2 configuration file (create Struts.xml file in src directory)
4. Create ACTION (action is a Pojo class)
4.1. Write the Execute method for action
4.2. Configure the action and return result set in the Struts.xml file

Struts development < configuring struts in eclipse. A >

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