Struts2初次配置启动tomcat出错

开发环境:
Eclipse Java EE IDE for Web Developers.

Version: Helios Service Release 1
Build id: 20100917-0705

Tomcat 6.x log:
[code="txt"]
2011-1-6 0:04:30 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2Demo' did not find a matching property.
2011-1-6 0:04:30 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_02\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jdk1.6.0_02/bin/../jre/bin/client;C:/Program Files/Java/jdk1.6.0_02/bin/../jre/bin;C:/Program Files/Java/jdk1.6.0_02/bin/../jre/lib/i386;C:\Program Files\PC Connectivity Solution\;C:\Program Files\Java\jdk1.6.0_02\bin;C:\Program Files\Java\jre1.6.0_02;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\EmEditor;C:\Program Files\TortoiseSVN\bin
2011-1-6 0:04:30 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2011-1-6 0:04:30 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 759 ms
2011-1-6 0:04:30 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2011-1-6 0:04:30 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.16
2011-1-6 0:04:30 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:249)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-1-6 0:04:30 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2011-1-6 0:04:30 org.apache.catalina.core.StandardContext start
严重: Context [/Struts2Demo] startup failed due to previous errors
2011-1-6 0:04:30 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2011-1-6 0:04:30 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2011-1-6 0:04:30 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/31 config=null
2011-1-6 0:04:30 org.apache.catalina.startup.Catalina start
信息: Server startup in 622 ms
[/code]

web.xml如下:
[code="java"]
<?xml version="1.0" encoding="UTF-8"?>

Struts2Demo

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

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>


[/code]

在xml中右键点击:org.apache.struts2.dispatcher.FilterDispatcher,可以进入FilterDispatcher类。

我在网上搜了下,提供的解决方案有:
1、导入commons-fileupload.jar和commons-io.jar包

2、将tomcat及jdk版本更新到struts2的需求,即5.5及1.5

3、添加struts2开发所需完整jar包

4、检查web.xml及struts.xml是否书写错误

5、将struts2相关包手动添加到classpath中
除了5我都试过,没有问题。
引入的jar包,见下图:
[img]http://dl.iteye.com/upload/attachment/383348/cc12094e-5796-379c-b2f8-2facfb753bc6.jpg[/img]
PS:我十分想将红圈里的那俩东西删掉,但是也不知道怎么搞。我是建立的Dynamic Web Project,建完之后就带着了,删不掉。

15个回答

[quote]这个帖子中的配置界面怎么进入,我的情况很可能就是这个问题。
http://www.iteye.com/topic/378912 [/quote]

双击Servers面板的
Tomcat v6.0 Server at localhost

再点击Open launch configuration(打开运行配置)

看起来似乎没什么问题
最简单的配置如下:
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
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.FilterDispatcher
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>


[/code]

Struts2最基本的包:
commons-logging-1.0.4.jar
freemarker-2.3.10.jar
ognl-2.6.11.jar
struts2-api-2.1.0.jar
struts2-core-2.1.0.jar
xwork-2.1.0.jar
有这几个对于简单的例子就够用了

1、建议重新复制一份可以运行的web.xml覆盖原来的文件,手工配置相关参数,这样是为了排除web.xml中包含特殊字符所造成的问题
2、在Java代码中输入使用org.apache.struts2.dispatcher.FilterDispatcher,看能不能引用到该类,此处用于确认jar确实被项目引用到了
3、将项目打包的war包,或者直接拷贝项目相关文件到Tomcat中的webapps中,启动Tomcat运行看是否有错误,此处如果成功,说明代码没问题,是在Eclipse中配置造成的问题

简单例子:
web.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
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">
Struts 2.0 Hello World

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

[/code]

Struts配置:
[code="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">




HelloWorld.jsp



[/code]

Action类:
[code="java"]
/**

  • */ package tutorial;

import com.opensymphony.xwork2.ActionSupport;

/**

  • @author qiuzj
  • */
    public class HelloWorld extends ActionSupport {
    private String name;

    /**

    • @return the name */ public String getName() { return name; }

    /**

    • @param name
    • the name to set */ public void setName(String name) { this.name = name; }

    @Override
    public String execute() {
    name = "Hello, " + name + "!";
    return SUCCESS;
    }

}

[/code]

页面:
[code="html"]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here


Your name is:


[/code]

访问地址:
http://主机名:端口号/应用名称/HelloWorld.action

做Java EE的开发,一般使用是
Eclipse IDE for Java EE Developers

你的红圈部分是因为你开的窗体视图的原因 没有关系的把视图在右上角有个表格似的东西 切换一下就好了。
你在看一下你的strut2-core-2.2.1.jar 这个包没有真实导入进你的项目。
仔细看你会发现core包的小瓶图标和别的包不一样,多了一个文件类似的图标,这说明没有真实导入。
建议:building path->Libraries->Add Jars 把包导入
如果不行 把包删除 重新导入一个 就好了。

[quote]
production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_02\bin;...[/quote]

是不是你的jdk没配置好呢?没找到?
building path->Libraries->选择jre
然后在右侧选择Edit,弹出框选择中间一个单选,在下拉中选择你的jdk

实在不行你就重新建立一个项目 不要碰那些自动生成的东西。
把那几个常用的包导入。重新做一遍,只要环境配置没问题,应该是行的通的。都是这么过来的,不可能到你这就不好使了。

FilterDispatcher现在是过期了,不过能用。

官方说明:

  • @deprecated Since Struts 2.1.3, use {@link org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter} instead or
  • {@link org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter} and {@link org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter}
  • if needing using the {@link ActionContextCleanUp} filter in addition to this one

现在的配置一般如下:
[code="xml"]
<!-- Struts2 filter -->

struts2CleanupFilter
org.apache.struts2.dispatcher.ActionContextCleanUp

<filter>
    <filter-name>struts2Filter</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2CleanupFilter</filter-name>
    <url-pattern>*.action</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

<filter-mapping>
    <filter-name>struts2Filter</filter-name>
    <url-pattern>*.action</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

[/code]

你可以重建个web工程试试

Tomcat5.5之后支持 version="2.4", 即支持servlet 2.4

如果加上后面一段就报错那可能有问题了,报的什么错误??

创建动态Web项目的时候
Dynamic web module version选项不要选择2.5,选择2.4

共15条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问