---
title: "Struts2七日学（第一日）"
author: "pointC"
date: "2012-01-10T01:17:37Z"
tags: []
categories: ["编程语言"]
slug: "struts2"
draft: false
lastmod: "2012-01-10T01:17:37Z"
id: 1339114
url: "https://pointc.iteye.com/blog/1339114"
---

第一日： 
今天主要学习了Struts2的配置，和一些概念。
nameSpace Action 等

关于配置和使用到的jar文件，大家可以参考 
struts-2.3.1.1\apps\struts2-blank.war (使用rar解压查看即可)

配置：
1）web.xml

```java

    <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>


```


2）struts.xml


```java

	<!-- 开发模式，修改配置后不需要重启服务器，但上线后应该设置为false -->
	<constant name="struts.devMode" value="true" />
	<package name="default" namespace="/" extends="struts-default">
		<action name="hello2">
			<result>
				hello.jsp
			</result>
		</action>
	</package>


```


关于需要的jar,个人觉得用到什么加什么，看出来什么错，缺了什么包，再加比较好

   Errot:

    java.lang.IllegalStateException: Must have the StrutsPrepareFilter execute before this one

    这里要注意struts2使用的Filter是org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    struts2-core-2.3.1.jar

    java.lang.NoClassDefFoundError: com/opensymphony/xwork2/ActionContext

    xwork-core-2.3.1.jar

    java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

    commons-lang-2.5.jar

    java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils

    基本需要的jar:

    commons-fileupload-1.2.2.jar

    commons-io-2.0.1.jar

    commons-lang-2.5.jar

    freemarker-2.3.18.jar

    javassist-3.11.0.GA.jar

    ognl-3.0.3.jar

    struts2-core-2.3.1.jar

    xwork-core-2.3.1.jar