没有为动作com.ril.tc.action.LoginAction和结果成功定义结果

时间:2013-10-04 05:36:15

标签: java struts2

我在Struts2中创建LoginAction。我创建了LoginAction类并在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>
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources"
        value="ApplicationResources" />
   <package name="default" extends="struts-default">
      <action name="index">
            <result>jsp/index.jsp</result>
      </action>   

      <action name="login"
            class="com.ril.tc.action.LoginAction">
            <result name="success">jsp/index.jsp</result>
            <result name="error">jsp/account/login.jsp</result>
        </action> 
   </package>
</struts>

动作类如下

package com.ril.tc.action;

import org.springframework.beans.factory.annotation.Autowired;  
import com.ril.tc.common.*;
import com.ril.tc.service.LoginService;

public class LoginAction extends BaseAction{

    private static final long serialVersionUID = -2112196951962991452L;
    private String username;
    private String password;

    @Autowired
    private LoginService loginService;

    public String execute() {       

        if (this.username.equals("admin") && this.password.equals("admin123")) {
            loginService.getUserList();
            return "success";
        } else {
            addActionError(getText("error.login"));
            return "error";
        }
    }

    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;
    }
}

但是当我执行loginAction时,我收到以下错误。

INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
ERROR [http-bio-8080-exec-3] (CommonsLogger.java:38) - Could not find action or result
/TransConnect/login.action
No result defined for action com.ril.tc.action.LoginAction and result success 

我没有得到什么问题。我已经提到了reult“成功”和各自的行动。

1 个答案:

答案 0 :(得分:1)

您的代码:

<action name="login" class="com.ril.tc.account.LoginAction">
        <result name="success">jsp/index.jsp</result>
        <result name="error">jsp/account/login.jsp</result>
</action> 

您的错误:

  

没有为行动com.ril.tc.action.LoginAction定义结果并且结果成功

将它们放在另一个之下:

  

com.ril.tc.的帐户 .LoginAction
  com.ril.tc.的作用 .LoginAction

:)

  

无法找到行动或结果”

找不到动作,而不是结果。更改包或更改struts配置以使其正常工作...