最近在学Struts2 在配置的时候有问题了,我去!看着书上的去Apache(http://struts.apache.org)网站下好Struts2的Jar包,解压后,选了几个JAR文件,放到项目Lib下,然后是配置 web.xml 如下:
<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>
把上面的配置写到<webapp>下即可;
但是在启动tomcat的时候就有错误了如下:
[color=red]警告: Could not create JarEntryRevision for [jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar]
...
2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-default.xml]
2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
严重: Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
...
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
...
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
...
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start
严重: Context [/Struts2] startup failed due to previous errors[/color]
刚开始以为是JDK版本过低,然后后去下了最新JDK,还是不行,最后在网上找到解决方法如下:
在Struts 2.2.x中应该导入如下7个JAR文件
1) commons-fileupload-1.2.1.jar
2) commons-io-1.3.2.jar
3) freemarker-2.3.16.jar
4) javassist-3.7.ga.jar
5) ognl-3.0.jar
6) struts2-core-2.2.1.jar
7) xwork-core-2.2.1.jar
其实,我们可以将Struts 2.2.x根目录下的apps文件夹下的struts2-blank-2.2.1.war文件进行解压,然后找到WEB-INF下的lib目录,我们可以发现里面列出了7个JAR文件,刚好这7个就是我们配置Struts 2.2.x需要导入的JARs文件
接下来启动你的Tomcat吧,天下太平,哈哈!
现在我们的tomcat已经启动了,但项目里面还没有struts.xml文件,在项目src下新建一个xml文件然后,把下面的代码放进去就OK了,当然Action节点中的内容要你自己去写了
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="buyer" extends="struts-default">
<action name="login" class="com.project.Action.LoginAction">
<result name="success">/XWEB/UserManager/Result.jsp</result>
<result name="error">/XWEB/UserManager/Error.jsp</result>
</action>
</package>
</struts>
另外要注意的一点是一定要在XML文件中加入
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
要不启动Tomcat的时候还有可能有错误!
<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>
把上面的配置写到<webapp>下即可;
但是在启动tomcat的时候就有错误了如下:
[color=red]警告: Could not create JarEntryRevision for [jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar]
...
2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-default.xml]
2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
严重: Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
...
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
...
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
...
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start
严重: Context [/Struts2] startup failed due to previous errors[/color]
刚开始以为是JDK版本过低,然后后去下了最新JDK,还是不行,最后在网上找到解决方法如下:
在Struts 2.2.x中应该导入如下7个JAR文件
1) commons-fileupload-1.2.1.jar
2) commons-io-1.3.2.jar
3) freemarker-2.3.16.jar
4) javassist-3.7.ga.jar
5) ognl-3.0.jar
6) struts2-core-2.2.1.jar
7) xwork-core-2.2.1.jar
其实,我们可以将Struts 2.2.x根目录下的apps文件夹下的struts2-blank-2.2.1.war文件进行解压,然后找到WEB-INF下的lib目录,我们可以发现里面列出了7个JAR文件,刚好这7个就是我们配置Struts 2.2.x需要导入的JARs文件
接下来启动你的Tomcat吧,天下太平,哈哈!
现在我们的tomcat已经启动了,但项目里面还没有struts.xml文件,在项目src下新建一个xml文件然后,把下面的代码放进去就OK了,当然Action节点中的内容要你自己去写了
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="buyer" extends="struts-default">
<action name="login" class="com.project.Action.LoginAction">
<result name="success">/XWEB/UserManager/Result.jsp</result>
<result name="error">/XWEB/UserManager/Error.jsp</result>
</action>
</package>
</struts>
另外要注意的一点是一定要在XML文件中加入
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
要不启动Tomcat的时候还有可能有错误!