问题描述
在搭建struts2环境的时候,拷贝了web.xml,拷贝了struts.xml,拷贝了jar包。运行,正常,访问jsp页面,报404错误。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://xmlns.jcp.org/xml/ns/javaee"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"id="WebApp_ID" version="3.1"><display-name>hellostruts2</display-name><filter><filter-name>struts</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
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><package name="xxxx" extends="struts-default"><action name="hello" class="com.zengmg.strtus.HelloAction" method="execute"><result name="success">/success.jsp</result></action></package></struts>
访问:
http://localhost:8080/strutsfiledemo/success.jsp。报 404!
原因:
因为struts.xml配置了的action没有java类与其对应,所以报错。但是我没把控制台的信息拉到上面看,导致没看到信息。
Caused by: Action class [com.zengmg.strtus.HelloAction] not found - action - file:/E:/apache-tomcat-8.0.26/webapps/strutsfiledemo/WEB-INF/classes/struts.xml:8:82
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:434)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:378)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:495)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:286)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:234)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 16 more
解决方法:
把struts.xml的action删了,或者写好java类,配置正确action。