启动tomcat服务器时获取异常(9.0)

时间:2018-02-06 11:11:36

标签: java eclipse maven struts2

Exception is :  `SEVERE: Exception starting filter [struts2]
 java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:104)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4491)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5131)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1425)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1415)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1425)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1415)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:941)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:671)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)`

我是struts的新手,我将struts.xml文件保存在项目目录的资源文件夹下。 我的struts.xml是

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts 
Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="abc" extends="struts-default">
<action name="login">
<result >login.jsp</result>
</action>
<action name="loginprocess" class="com.javatpoint.Login">
<result name="success"  >loginsuccess.jsp</result>
<result name="error" >loginerror.jsp</result>
</action>
<action name="logout" class="com.javatpoint.Login" method="logout">
<result name="success" >logoutsuccess.jsp</result>
</action>
<action name="profile" class="com.javatpoint.Profile">
<result name="success" >profilesuccess.jsp</result>
<result name="error" >profileerror.jsp</result>
</action>
</package>
</struts>

是否必须在web.xml中添加侦听器类? web.xml是:

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>   
<display-name>Archetype Created Web Application</display-name>
<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>
</web-app>

pom.xml是

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>StrutsLogin</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>StrutsLogin Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-core -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.10.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<finalName>StrutsLogin</finalName>
</build>
</project>

以上代码来自基础教程,而即时执行jsp文件即时获取404错误,而我启动tomcat服务器即可获得上面显示的异常。

更改了评论中的内容,例如==我在web.xml中更改了,在struts.xml中更改了dtd,现在我得到了内部服务器错误

HTTP Status 500 – Internal Server Error
Type Exception Report
Message Illegal char <:> at index 3: 
jar:file: 
\D:\Sworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtp
webapps\StrutsLogin\WEB-INF\lib\struts2-core-2.5.10.1.jar
Description The server encountered an unexpected condition that prevented 
it from fulfilling the request.
Exception
java.nio.file.InvalidPathException: Illegal char <:> at index 3: 
jar:file:\D:\Sworkspace 
\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\
StrutsLogin\WEB-INF\lib\struts2-core-2.5.10.1.jar
java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
java.base/java.io.File.toPath(File.java:2300)
java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:951)
java.base/java.util.zip.ZipFile.<init>(ZipFile.java:216)
java.base/java.util.zip.ZipFile.<init>(ZipFile.java:148)
java.base/java.util.jar.JarFile.<init>(JarFile.java:324)
java.base/java.util.jar.JarFile.<init>(JarFile.java:295)
java.base/java.util.jar.JarFile.<init>(JarFile.java:234)
com.opensymphony.xwork2.util.fs.JarEntryRevision.needsReloading(JarEntryRevision.java:73)
com.opensymphony.xwork2.util.fs.DefaultFileManager.fileNeedsReloading(DefaultFileManager.java:62)
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.needsReload(XmlConfigurationProvider.java:425)
org.apache.struts2.config.StrutsXmlConfigurationProvider.needsReload(StrutsXmlConfigurationProvider.java:163)
com.opensymphony.xwork2.config.ConfigurationManager.needReloadContainerProviders(ConfigurationManager.java:212)
com.opensymphony.xwork2.config.ConfigurationManager.conditionalReload(ConfigurationManager.java:178)
com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:73)
org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:906)
org.apache.struts2.dispatcher.ExecuteOperations.executeStaticResourceRequest(ExecuteOperations.java:59)
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:130)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/9.0.2

现在它工作正常,我在maven依赖中更改了struts2core版本..谢谢。

2 个答案:

答案 0 :(得分:0)

过滤器类已移至父包。

您应该更改Web部署描述符中StrutsPrepareAndExecuteFilter的过滤器包位置。

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

答案 1 :(得分:-1)

从Maven pom.xml看来你有Struts2.5的库,你使用的是2.1的DTD。因此,请尝试更新提供的两个更改。感谢

替换struts2.xml的第一行,即

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

并在web.xml中用此

替换过滤器
<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>