0

I am creating LoginAction in Struts2. i have created the LoginAction class and configured in struts.xml as follows.

<?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 class is as follows

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

But when i executes the loginAction i receives below error.

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 

I am not getting what is the problem. i have mentioned the reult "success" and respective action.

Abhijit
  • 673
  • 2
  • 17
  • 35

1 Answers1

1

Your code:

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

Your error:

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

Put them one below the other:

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

:)

"Could not find action or result"

It can't find the Action, not the result. Change the package or change struts config to make it works...

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • thanks @Andrea Ligios. by mystically i changed the struts.xml. even when i change to com.ril.tc.action.LoginAction i gets same error, in fact initially i had added LoginAction in account pkg. that time it was working fine. but when i changed to action pkg it started giving error. finally i changed the action name from login to userLogin. now its working fine. – Abhijit Oct 04 '13 at 09:45