最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

struts2访问jsp页面404

旗下网站admin41浏览0评论

struts2访问jsp页面404

struts2访问jsp页面404

问题描述

在搭建struts2环境的时候,拷贝了web.xml,拷贝了struts.xml,拷贝了jar包。运行,正常,访问jsp页面,报404错误。



web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	xmlns=""
	xsi:schemaLocation=" .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"
          ".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。


发布评论

评论列表(0)

  1. 暂无评论