-1
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)`

I kept the struts.xml file under resource folder of project directory.

My struts.xml is:

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

Does it mandatory to add listener class in the web.xml?

web.xml is :

<!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 is:

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

The above code is from basic tutorial. While I'm executing the JSP files I'm getting 404 error. While I'm starting the Tomcat server I'm getting the exception shown above.

After changing the things from comments like: I changed <filter-class> in web.xml and DTD in struts.xml.

Now I'm getting internal server error:

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

Now it is working fine. I changed struts2-core version in Maven dependency.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Sai
  • 5
  • 7
  • Possible duplicate of [Exception starting filter struts2 java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter](https://stackoverflow.com/questions/23421278/exception-starting-filter-struts2-java-lang-classnotfoundexception-org-apache-s) – Laurent B Feb 06 '18 at 11:14
  • @Laurent This is different problem. – Roman C Feb 06 '18 at 17:04
  • This is illegible; please indent XML properly so we can actually read it. – Dave Newton Feb 07 '18 at 14:34

2 Answers2

0

The filter class has moved to the parent package.

You should change the filter package location of the StrutsPrepareAndExecuteFilter in your web deployment descriptor.

<filter-class>
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • i changed now im getting another error 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\wtpwebapps\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 – Sai Feb 07 '18 at 04:58
  • 1
    @Sai So fix your file. – Dave Newton Feb 07 '18 at 14:34
0

From Maven pom.xml it seems you have library of Struts2.5 and you are using DTD of 2.1. So try updating the the two changes provided. Thanks

Replace your first line of struts2.xml i.e

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

and in web.xml replace the filter with this

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
  • i updated now im getting 500 error check below 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\wtpwebapps\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 – Sai Feb 07 '18 at 05:06
  • Please check if syntax mistake in struts.xml or web.xml, as error is saying illegal char <. Paste same values in both files, as I have posted. – Mrunmay Deswandikar Feb 07 '18 at 06:47
  • also if possible, clear log files, and paste the log of error here, located in "logs" folder if you are using tomcat. – Mrunmay Deswandikar Feb 07 '18 at 06:49