Struts2 第一篇 struts2 环境的搭建

来源:互联网 发布:安卓收银软件 编辑:程序博客网 时间:2024/05/01 19:40

本系列是记录学习Struts 2 的过程。

Struts 2 官方下载链接:http://struts.apache.org/2.1.8.1/index.html,可以下载最新版本的Struts2.1.8。

 

搭建 struts 2 环境:

1.所需jar包: struts2-core-2.1.8.1.jar, xwork-core-2.1.6.jar,ognl-2.7.3.jar,freemarker-2.3.15.jar,commons-fileupload-1.2.1.jar,commons-logging-1.0.4.jar

2. struts2 配置文件 struts.xml

3.web.xml 中加入struts的配置

 

struts.xml

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

</struts>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
   
    <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>
   
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
   <jsp-config>
        <taglib>
              <taglib-uri>/WEB-INF/struts-tags.tld</taglib-uri>
             <taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
        </taglib>
      </jsp-config>
</web-app>

 

 

配置 strutsfilter 时也可以用<filter>  
        <filter-name>struts2</filter-name>  
        <filter-class>  
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>  
    </filter>

但是2.1.6 后 struts开始用 StrutsPrepareAndExecuteFilter 代替 FilterDispatcher。所以建议使用StrutsPrepareAndExecuteFilter。

原创粉丝点击