struts2跳转,404!百思不知道哪里错了

zhouchunlan89 2011-06-21 10:40:43
简单的测试一个跳转,报错,请看看是什么原因?
WebContent下面文件内容:
index.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="toWelcome.action">login on</a>
</body>
</html>

welcome.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
welcome to this!
</body>
</html>

src下面有一个action包,包里面有文件如下:

Welcome.java:
package action;

import com.opensymphony.xwork2.ActionSupport;

public class Welcome extends ActionSupport{
public String toWel(){
return SUCCESS;
}
}

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="action" extends="struts-default" namespace="/" >
<action name="toWelcome" class="action.Welcome" method="toWel">
<result>welcome.jsp</result>
</action>

</package>
</struts>
...全文
436 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxy15329 2011-06-24
  • 打赏
  • 举报
回复
如果没有在web.xml中添加struts2的过滤器也会出现找不到页面的情况
ChengLyn 2011-06-24
  • 打赏
  • 举报
回复
你敢不敢把你项目的目录结构以及你跳转的uri放个图出来,
zhangxiaoming1988 2011-06-24
  • 打赏
  • 举报
回复
这个问题我也遇到过,是路径问题。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">//注意的地方
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="toWelcome.action">login on</a>
</body>
</html>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="toWelcome.action">login on</a>
</body>
</html>
zhouchunlan89 2011-06-24
  • 打赏
  • 举报
回复
问题已经找到:1.过滤器未添加
但是上面有高手指点过这个问题,我也添加了,为什么还是不行呢?
最后发现是因为第二个问题:JAR包。因为JAR包里面除了STRUTS需要的,我还放了一些SPRING需要的,我以为不影响,有STRUTS需要的JAR就可以了,多了其他的没问题,事实上不是,有很大滴问题啊。。。。。

结帖,给分!!
五哥 2011-06-23
  • 打赏
  • 举报
回复
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="action" extends="struts-default" namespace="/" >
<action name="toWelcome" class="action.Welcome" method="toWel">
<result>/welcome.jsp</result> </action>

</package>
</struts>
talba0101 2011-06-23
  • 打赏
  • 举报
回复
配置文件出现的错误,可能是命名空间的问题
<action name="toWelcome" class="action.Welcome" method="toWel">
<result name="SUCCESS">welcome.jsp</result>
<result name="namespace">/</result>
</action>




summing_up 2011-06-23
  • 打赏
  • 举报
回复
配置文件出现的错误,可能是命名空间的问题
<action name="toWelcome" class="action.Welcome" method="toWel">
<result name="SUCCESS">welcome.jsp</result>
<result name="namespace">/</result>
</action>
romanitc 2011-06-23
  • 打赏
  • 举报
回复
貌似路径问题,测试不同的路径,就可以找出出错原因!
zhouchunlan89 2011-06-23
  • 打赏
  • 举报
回复
命名空间和路径都照上楼的进行过检查,修改,测试,仍然404,有木有啊。。。太气人了。。。求真相。。。
xinghen88 2011-06-23
  • 打赏
  • 举报
回复
<a href="toWelcome.action">login on</a>
这个路径配的不对,前面加上你struts.xml中存放action的包名
tyjhField 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhouchunlan89 的回复:]
welcome.jsp在WebContent下
报错如下:
HTTP Status 404 - /Product/toWelcome.action

--------------------------------------------------------------------------------

type Status report

message /Produc……
[/Quote]

提示是 /Product/welcom.jsp

你试一试 ./Product/welcom.jsp
用 单点 表示根目录
zhouchunlan89 2011-06-22
  • 打赏
  • 举报
回复
上面各位的方法都试过了 还是404 还有木有办法??求真相帝。。。。。

HTTP Status 404 - /Product/toWelcome.action

--------------------------------------------------------------------------------

type Status report

message /Product/toWelcome.action

description The requested resource (/Product/toWelcome.action) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.18

zhouchunlan89 2011-06-22
  • 打赏
  • 举报
回复
/Product/toWelcome.action??

LZ你的路径是这样的吗?

我的是这样的
WebContent 下面的index.jsp是这样的:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="toWelcome.action">login on</a>
</body>
</html>
RuanJava 2011-06-22
  • 打赏
  • 举报
回复
<result name="SUCCESS">/welcome.jsp</result>
yhh0427 2011-06-22
  • 打赏
  • 举报
回复
<result name="SUCCESS">/welcome.jsp</result>
桃园闲人 2011-06-22
  • 打赏
  • 举报
回复
这里的namespace要么就不给,要给就这样namespace="/path",最好不要这样namespace="/"

这人认为,好久都没写了。你试试看。
桃园闲人 2011-06-22
  • 打赏
  • 举报
回复
<a href="toWelcome.action">login on</a>改成这样
<a href="/toWelcome.action">login on</a>

<package name="action" extends="struts-default" namespace="/" >
这里
24K純帥 2011-06-22
  • 打赏
  • 举报
回复
LZ你配置文件有<package name="action",页面也要加上
致知Fighting 2011-06-22
  • 打赏
  • 举报
回复
/Product/toWelcome.action??

LZ你的路径是这样的吗?
555555555555555 2011-06-22
  • 打赏
  • 举报
回复
The requested resource (/Product/toWelcome.action) is not available.

<?xml version="1.0" encoding="UTF-8"?>
<struts>
<package name="action" extends="struts-default" namespace="/" >
<action name="toWelcome" class="action.Welcome" method="toWel">
<result>welcome.jsp</result>
</action>
</package>
</struts>
加载更多回复(7)

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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