Struts2-安装


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






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值