日期:2014-05-17  浏览次数:20754 次

在action中execute能执行但是在return时出现404只是为啥呀,请大侠们帮忙呗!
我struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="Scopename" namespace="" extends="struts-default">
<action name="login" class="actions.LoginAction">
<result name="success" >/findLover.jsp</result>
<result name="error" >/Login.jsp</result>
</action>
<action name="register" class="actions.UserRegisterAction">
<result name="success" type="dispatcher">/Login.jsp</result>
<result name="error" type="dispatcher">/FailureRegister.jsp</result>
</action>
</package>

</struts>  


提交的Login.jsp 为:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢迎登录交友网</title>


</head>
<body>

<form method="post" action="login.action"
style="background-color: rgb(20, 96, 85);">
<center>

<font color="#800040">赶快登陆吧</font>
</center>

<hr>

用户名:
<input id="userNameID" type="text" name="name" align="left"
onblur="jadgeuserName()">
<span id="TwouserNameID" style="color: red; font-size: medium;"></span>

<br>

<br>
&nbsp; 密码&nbsp; :
<input type="password" id="passwordID" maxlength="100"
name="Pwd" onblur="">
<span id="TwopasswordID" style="color: red; font-size: medium;"></span>

<input type="submit" value="用户登录" name="" size="10%"
id="submitID" >
</form>
</body>
</html>



LoginAction为:运行的时候能够打印出System.out.println("LoginAction中已经执行!");语句的但是在return的时候就出现404了


package actions;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
private String name;
private String Pwd;
public String execute(){
System.out.println("LoginAction中已经执行!");
return SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return Pwd;
}
public void setPwd(String pwd) {
Pwd = pwd;
}

}


项目的布置如下:
jsp页面全部放在webRoot目录之下



希望大侠们一定要帮帮我啊,谢谢了.我始终没发现配置错在哪里




------解决方案--------------------
跟踪一下/findLover.jsp是否应该在正确的位置:
在login.jsp中加入如下语句:
<%
out.println("application.getRealPath=["+application.getRealPath("/findLover.jsp")+"]<br>");
%>
估计是你的根站点不一定是WebRoot。
------解决方案--------------------
还有一种在Action中获取URL的实际路径方法:
在execute()方法中加入:
System.out.println("/findLover.jsp="+ServletActionContext.getServletContext().getRealPath("/findLover.jsp");