The following example uses the STRUTS2 version of the Struts2 2.2.3.1 as the application by establishing a small instance specifically for the Eclipse integration struts2.
1. Download the STRUTS2 Development Kit
First step: Enter http://apache.org in the browser
Step two: Select the struct click link in the Apche page project to enter the relevant page
Step three: Click download Select Download Struct2, this example select: Struts2 2.2.3.1, after downloading, the Lib in the Strut2 in the development of the package used.
2. Build a Web Project
First step: Open Eclipse Click [File]->dynamic Web Project, enter relevant information such as:
Step two: Refer to the Java Development Kit Tomcat package and the STRUTS2 prerequisites package.
(1) Apply the Tomcat server package file
A. Right-struts2-> Click Properties and select Java Build path->libraries on the left
(2) Add JRE package file
A. Right-struts2-> Click Properties and select Java Build path->libraries on the left
Click OK when you are finished adding.
Step three: Strust2 development Lib package directly copy to Web-inf/lib below can
Establishment of an instance:
1. First describe the files that the instance contains: Struts.xml, Helloworldaction Java class, Web. XML, helloworld.jsp,index.jsp
2. The contents are as follows:
(1) 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><constant name=" Struts.devmode "value=" true "/> <package name= "HelloWorld" extends= "Struts-default" > <action name= "Hello" class= " Com.northeasttycoon.struts2.HelloWorldAction " method=" execute "> <result name=" Success ">/ helloworld.jsp</result> </action> </package></struts>
(2) Web. xml
<?xml version= "1.0" encoding= "UTF-8"?><!--northeasttycoon--><web-app xmlns:xsi= "http://www.w3.org/ 2001/xmlschema-instance "xmlns=" Http://java.sun.com/xml/ns/javaee "xsi:schemalocation=" http://java.sun.com/xml/ Ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "> < Display-name>struts 2</display-name> <welcome-file-list> <welcome-file>index.jsp </welcome-file> </welcome-file-list> <filter> <filter-name>struts2</ filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </ filter-class> </filter> <filter-mapping> <filter-name>struts2</ filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
(3) Helloworldaction.java
/** * @author Northeasttycoon * */package com.northeasttycoon.struts2;public class helloworldaction{ private String Name; Private String PassWord; Public String GetPassword () {return passWord;} public void SetPassword (String passWord) {This.password = PassWord;} Public String Execute () throws Exception { return "success"; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; }}
(4) helloworld.jsp
<%@ page contenttype= "text/html; Charset=utf-8 "%><%@ taglib prefix=" s "uri="/struts-tags "%>
(5) index.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" UTF-8 "%><%@ taglib prefix=" s "uri="/struts-tags "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The above is an example of the entire content after debugging.
Effects such as:
Note:
Northeast Tycoon
Blog: http://www.cnblogs.com/northeastTycoon/p/5617958.html
Copyright for the individual, you are welcome to reprint, but the reprint must indicate the source of the article, and at the beginning of the article is clearly linked to the Ming.
STRUTS2 Eclipse Integrated STRUST2 Development Framework Example