Struts2-安装

来源:互联网 发布:unity3d人物模型在哪里 编辑:程序博客网 时间:2024/06/05 09:00


http://struts.apache.org/release/2.3.x/docs/create-struts-2-web-application-with-artifacts-in-web-inf-lib-and-use-ant-to-build-the-application.html


Struts 2 requires Servlet API 2.4 or higher, JSP 2.0 or higher, and Java 5 or higher.

Add Struts 2 Jar Files To Class Path

Find and copy to WEB-INF\lib these files (note X.X.X.X.jar refers to the version number):

  1. asm-x.x.jar
  2. asm-commons-x.x.jar
  3. asm-tree-x.x.jar
  4. commons-io-X.X.X.jar
  5. commons-lang3-X.X.X.jar + commons-lang3-3.1.jar
  6. commons-fileupload-X.X.X.jar
  7. freemarker-X.X.X.jar
  8. javassist-X.X.X.jar
  9. ognl-X.X.X.jar
  10. struts2-core-X.X.X.X.jar
  11. xwork-core-X.X.X.jar



Add Struts 2 Servlet Filter

To enable the Struts 2 framework to work with your web application you need to add a Servlet filter class and filter mapping to web.xml. Below is the filter and filter-mapping nodes you should add to web.xml.

web.xml Servlet Filter
<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>

Create struts.xml

Struts 2 can use either an XML configuration file or annotations (or both) to specify the relationship between a URL, a Java class, and a view page (such as index.jsp). For our basic Struts 2 application, we'll use a minimal xml configuration. Note the file name is struts.xml and it should be in the src folder (struts.xml must be on the web application's root class path).

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="basicstruts2" extends="struts-default"><action name="index"><result>/index.jsp</result></action></package></struts>

Build and Run the Application






原创粉丝点击