[英]Java Struts2 (Action class not found)
The error which I am getting.我得到的错误。 It was running all fine a day before but when open it today I get the following errors.
前一天运行良好,但今天打开时出现以下错误。
Action class [com.tutorialspoint.struts2.HelloWorldAction] not found - action - file:/C:/Users/sai/Struts2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/HelloWorldStruts2/WEB-INF/classes/struts.xml:10:30
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:374)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:329)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:429)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:239)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:152)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:205)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4828)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5508)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
My index.jsp page我的 index.jsp 页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World From Struts2</h1>
<form action="hello">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</form>
</body>
</html>
My struts.xml file我的 struts.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">
<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello"
class="com.tutorialspoint.struts2.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
<result name="error">/AccessDenied.jsp</result>
</action>
</package>
</struts>
The action mapping ---- I tried hello as action name and also hello.action as action name but got the same error动作映射 ---- 我尝试将 hello 作为动作名称,也尝试将 hello.action 作为动作名称,但得到了相同的错误
My web.xml file我的 web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
Even after cleaning the project redeploying it and again restarting the server I was not able to remove the error.即使在清理项目并重新部署它并再次重新启动服务器之后,我也无法消除错误。
Struts2 XML configuration provider cannot load the action class. Struts2 XML 配置提供程序无法加载操作类。 This class
com.tutorialspoint.struts2.HelloWorldAction
is not available on the classpath or corrupted.此类
com.tutorialspoint.struts2.HelloWorldAction
在类路径上不可用或已损坏。 The version are you using is too old, and you need to recreate the project and update version information in xml configuration files struts.xml
, web.xml
.您使用的版本太旧,您需要重新创建项目并更新 xml 配置文件
struts.xml
、 web.xml
版本信息。
See How To Create A Struts 2 Web Application .请参阅如何创建 Struts 2 Web 应用程序。
In my case, a simple mistake occurred on project build path: I placed the JRE Library and Maven Dependencies on top of src/main/java and src/main/resources.就我而言,在项目构建路径上发生了一个简单的错误:我将 JRE 库和 Maven 依赖项放在 src/main/java 和 src/main/resources 之上。
The correct order in Project Java Build Path is: Project Java Build Path 中的正确顺序是:
src/main/java
src/main/resources
src/test/java
JRE System Library
Maven Dependencie
对我来说,只需清理项目,再次重建它并在 tomcat 上重新部署它就可以了。
Placed the struts.xml file in webcontent->web-inf folder.将 struts.xml 文件放在 webcontent->web-inf 文件夹中。 Hope it will solved ur problem.
希望它能解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.