intellij idea 使用struts2访问action时出现404错误

来源:互联网 发布:淘宝店铺可以不装修吗 编辑:程序博客网 时间:2024/05/23 00:05

错误如图,

struts.xml配置没错:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"        "http://struts.apache.org/dtds/struts-2.5.dtd">        <!-- 指定Struts 2配置文件的根元素 --><struts><!-- 指定全局国际化资源文件 --><constant name="struts.custom.i18n.resources" value="mess"/><!-- 指定国际化编码所使用的字符集 --><constant name="struts.i18n.encoding" value="GBK"/><!--指定constant的name为devMode表示处于开发模式,value=true修改配置文件内容自动热替换而不需要每次重新发布--><constant name="struts.devMode" value="true"/><!-- 所有的Action定义都应该放在package下,Struts2中通过package来管理action,这里的包名name并不对应java类中的包 --><package name="hello" extends="struts-default" >    <action name="HelloWordAction" class="Action.hello.HelloWordAction" >        <!-- 定义三个逻辑视图和物理资源之间的映射 -->        <result name="input">/login.jsp</result>        <result name="error">/error.jsp</result>        <result name="success">/success.jsp</result>    </action></package></struts>
后来发现是web.xml的配置有错,过滤器把action拦截了,在filter标签中添加<url-pattern>*.action</url-pattern>后问题解决。

web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"         version="3.1">    <welcome-file-list>        <welcome-file>index.jsp</welcome-file>    </welcome-file-list>    <filter>        <filter-name>struts2</filter-name>        <filter-class>            org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter        </filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>*.action</url-pattern>    </filter-mapping></web-app>




阅读全文
0 0
原创粉丝点击