花公子丶
2015-04-23 03:31
采纳率: 60%
浏览 2.6k
已采纳

struts2把Action配成login就报错,配成其他的就不会,这是为何?

jsp代码,就是在body上加个表单,表单内容如下:

<form action="login.action" method="post">
        <table>
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="user.username"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="user.password"></td>
            </tr>
            <tr>
                <td><input type="reset" value="重填"></td>
                <td><input type="submit" value="登录"></td>
            </tr>
        </table>
    </form> 

然后是Action

 public class LoginAction extends ActionSupport
{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private User user;
    @Override
    public String execute() throws Exception 
    {
        if("zhangsan".equals(user.getUsername())&&"123".equals(user.getPassword()))
        {
            System.out.println("SUCCESS 结果");
            return SUCCESS;
        }

        else
        {
            System.out.println("error结果");
            return ERROR;
        }
    }

    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }   
}

再然后是struts2的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="default" extends="struts-default">
        <action name="login" class="com.action.LoginAction">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
</struts>   

最后是一个javabean

 public class User implements Serializable
{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String username;
    private String password;

    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}

error.jsp与success.jsp随便写就好,然后运行就一直报No result defined for action com.action.LoginAction and result 的错误,只要把struts.xml文件跟上面给出的jsp form里的login改成其他任意名字,例如:hhh之后,就正常运行不再报错。这是为何?求各位帮个忙解答下,感激不尽

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

9条回答 默认 最新

  • 毕小宝 2015-04-23 04:26
    已采纳

    web.xml中struts配置的问题。祝好!

       <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>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(8条)

相关推荐 更多相似问题