Struts2在web.xml中配置后出现404错误

V0_fly 2016-10-03 02:30:43
在论坛里面查了很多关于这个错误的问题,但就是没得到解决,JSP界面单独能运行,但是要是把WEB.XML加上过滤器filter就出404错误了,检查了很多遍也找不到问题所在,请求帮助,代码如下:

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">
<!-- 配置Struts2核心控制器 -->
<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>



struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Struts2配置文件的根元素 -->
<struts>
<!-- Struts2的Action必须放在指定的包空间下定义 -->
<package name="hello" namespace="/" extends="struts-default">
<!-- 定义action,该,action对应的类为cn.itcast.action.HelloWorldAction类 -->
<action name="helloWorld" class="cn.itcast.action.HelloWorldAction">
<!-- 定义处理结果和试图资源之间的映射关系 -->
<result name="success">/success.jsp</result>
</action>
</package>
</struts>




Action:

package cn.itcast.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
@Override
public String execute() throws Exception {
// TODO 自动生成的方法存根
return SUCCESS;
}
}



index.jsp:


<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<html>
<head>
<title>首页</title>
</head>
<body>
<h1>Welcome To Struts2!</h1>
< <a href="${pageContext.request.contextPath}/helloWorld.action">
Hello World
</a>
</body>
</html>




success.jsp


<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>成功页面</title>
</head>
<body>
欢迎学习第一个Struts2程序!
</body>
</html>
...全文
1553 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
_童心_ 2018-01-09
  • 打赏
  • 举报
回复
楼主,怎么解决的?我是新手也遇到这个问题啦,急的我快疯了
liubo411215459 2017-02-15
  • 打赏
  • 举报
回复
楼主解决了吗? 我也是同样的问题
V0_fly 2016-10-10
  • 打赏
  • 举报
回复
引用 6 楼 zhuzige521888 的回复:
1.可能版本问题 <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> 2.尝试添加参数即action所在包 <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>com.cjm.web.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
回答的那么详细,虽然没解决问题。。但是也感谢您的热心指导,万分感谢
zhuzhuaicai 2016-10-09
  • 打赏
  • 举报
回复
楼主解决了吗?
Mop.Duan 2016-10-09
  • 打赏
  • 举报
回复
1.可能版本问题 <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> 2.尝试添加参数即action所在包 <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>com.cjm.web.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
V0_fly 2016-10-09
  • 打赏
  • 举报
回复
引用 4楼zhuzhuaicai 的回复:
楼主解决了吗?
并没有…等待解决呢
V0_fly 2016-10-08
  • 打赏
  • 举报
回复
没有人知道吗???你们注意看我的struts配置和web配置,我不知道错在哪里,但我把web.XML中的filter屏蔽之后index.jsp就能正常显示了,到底是什么原因嘛,求解
V0_fly 2016-10-08
  • 打赏
  • 举报
回复
引用 2楼zhuzhuaicai 的回复:
过滤器里怎么实现的?
过滤器配置就是web.XML中的内容,是将请求交给HelloWorldAction处理,上面
zhuzhuaicai 2016-10-08
  • 打赏
  • 举报
回复
过滤器里怎么实现的?

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧