当前位置: 代码迷 >> J2EE >> struts2中<result name这个name可以自定义吗,该如何解决
  详细解决方案

struts2中<result name这个name可以自定义吗,该如何解决

热度:30   发布时间:2016-04-22 00:29:11.0
struts2中<result name这个name可以自定义吗
这个name默认有success、input、error、login、none。但是我想问可以自定义吗?比如定义成<result name="ok">定义成ok。
如果可以,那我为什么我的代码运行报错呢,但是改为success又可以运行了。报错:HTTP Status 404 - No result defined for action com.wr.action.LoginAction and result success
action代码:
Java code
public String isLogin() {            HttpServletRequest request = null;                User u = new User();        u.setName(name);        u.setPwd(pwd);        u = loginService.isLogin(u);        if(u!=null) {            System.out.println("name"+name);            request.getSession().setAttribute("user", u);            return "ok";        }         return ERROR;    }

struts.xml代码:
Java code
<action name="login_isLogin" class="com.wr.action.LoginAction" >      <result name="ok">success.jsp</result>      <result name="error">error.jsp</result>         </action>

jsp代码
Java code
<form action="login_isLogin.action" method="post">      name:<input type="text" name="name"/><br>      pwd:<input type="password" name="pwd"/>      <input type="submit" value="登录"/><input type="reset" value="重置"/>     </form>


------解决方案--------------------
return ERROR 改成 return "error"; 试试
------解决方案--------------------
不肯能,肯定是你哪里写错了,

HTTP Status 404 - No result defined for action com.wr.action.LoginAction and result success
这句话意思是说 没有找到 result=success的配置

<action name="login_isLogin" class="com.wr.action.LoginAction" >
你的这个 配置 表示 默认调用execute,但是你贴出来的根本就不是,isLogin也没有配置动态方法, 所以你前面的测试全是execute()方法
  相关解决方案