日期:2014-05-20  浏览次数:20674 次

【100分】Action里面明明定义了result,但是报错说找不到result?
错误提示:No result defined for action action.LoginAction and result input
struts.xml如下:
XML code
<action name="login" class="action.LoginAction" method="login">
                <result name="input">/login.jsp</result>
                <result name="error">/error.jsp</result>
                <result name="success">/welcome.jsp</result>                    </action>

java代码:
Java code
public String login() {
        BusinessService service = new BusinessService();
        User user = service.login(getId(), getPassword());
        System.out.println(user.getId());
        //登录成功
        if(user!=null){
            ActionContext.getContext().getSession().put("user", id);
            System.out.println("登录成功");
            return SUCCESS;
        }
        return ERROR;
    }

程序已经能走进LoginAction里面的login函数,也已经进入返回success的代码块,但是出错,提示找不到result


------解决方案--------------------
Java code
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <base href="<%=basePath%>">

------解决方案--------------------
<result name="input">/login.jsp</result>
删除试下,你这个结果
 if(null!=user){
ActionContext.getContext().getSession().put("user", id);
System.out.println("登录成功");
return SUCCESS;
}
else{ return ERROR;
}
return INPUT;
好久不用,不知道是不是这问题
------解决方案--------------------
welcome.jsp放在哪个文件目录下?
------解决方案--------------------
你在每个result 里边加一个type="redirect" 即:<result name="success" type="redirect"> 然后看看跳转时候的地址是什么?记得改了xml要重启Tomcat,如果还不行,可以把Return换一个值,可以Return ‘s1’ 然把result的name也换了。。。
------解决方案--------------------
我晓得有种情况会出现这种错误,就是你的页面form里的input的name和action里面的属性名或类型不一致。
比如你这里,如果action里有id和password属性,如果你的页面上是user.id和user.password或者是Id和Password,那么就会出现找不到result。如果你页面上输入的id为字符串,但你action中的id为int,那么也会出现找不到result。