2013-10-04 33 views
0

我在Struts2中創建LoginAction。我已經創建了LoginAction類,並在struts.xml中進行了如下配置。沒有爲行動com.ril.tc.action.LoginAction和結果成功定義結果

<?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> 

Action類是如下

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 i接收如下錯誤。

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 

我沒有得到什麼問題。我已經提到了「成功」和相應的行動。

+0

你可以告訴你動作課嗎? –

+0

我已添加行動類。 – Abhijit

+0

當你得到這個錯誤時你打的是什麼URL? –

回答

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> 

你的錯誤:

No result defined for action com.ril.tc.action.LoginAction and result success

把它們放在一個低於其他:

com.ril.tc.account.LoginAction
com.ril.tc.action.LoginAction

:)

"Could not find action or result"

它找不到Action,而不是結果。更改包或更改struts配置,使其工作...

+0

謝謝@Andrea Ligios。我神祕地改變了struts.xml。即使當我更改爲com.ril.tc.action.LoginAction時,我也會得到相同的錯誤,事實上最初我在帳戶pkg中添加了LoginAction。那個時候它工作正常。但是當我改變爲行動pkg它開始給錯誤。最後我改變了從login到userLogin的動作名稱。現在它的工作正常。 – Abhijit