hi,
i encounter a problem after deploying war file to
jboss3.0.4-tomcat4.1.12 container. it issues error "
Cannot retrieve definition for form bean LoginAction";
yet i have already an action named LoginAction in the
folder. what might causes such error occurred?
the folder name space looks like:
com.oreilly.actions.* and com.oreilly.forms.*
and the source embedded with struts tag as follow:
the source, in fact, is derived from onjava.com's
sample with modifing its source code expcet adding
struts tag.
i appreciate any suggestions, sincerely.
thank you very much.
ps: there's no problem when generating meta files and
other source, except can't run through web. i suppose
i may lose some important tags yet i don't what it is.


===========Form=======
/*
 * LoginForm.java
 */
package com.oreilly.forms;


import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;


/**
 * @struts:form name="LoginForm"
 *
 * Form bean for the Login main page.  There are two
fields on this
 * form used for authentication
 * <ul>
 * <li>username - the username to login
 * <li>password - the password to authenticate
 * </ul>
 */
public final class LoginForm extends ActionForm  {
    private String userName = null;
    private String password = null;
    
    /**
     * Get the userName
     [EMAIL PROTECTED] String 
     */
    public String getUserName() {
        return (userName);
    }

    /**
     * Set the userName.
     * @param userName 
     */
    public void setUserName(String newUserName) {
        userName = newUserName;
    }

    /**
     * Get the password
     [EMAIL PROTECTED] String 
     */
    public String getPassword() {
        return (password);
    }

    /**
     * Set the password.
     * @param password 
     */
    public void setPassword(String newPassword) {
        password = newPassword;
    }


    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this
instance
     * @param request The servlet request we are
processing
     */
    public void reset(ActionMapping mapping,
HttpServletRequest request) {
        userName = null;
        password = null;
        
    }

    /**
     * Validate the properties that have been set from
this HTTP request,
     * and return an <code>ActionErrors</code> object
that encapsulates any
     * validation errors that have been found.  If no
errors are found, return
     * <code>null</code> or an
<code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this
instance
     * @param request The servlet request we are
processing
     */
    public ActionErrors validate(ActionMapping
mapping,
                                 HttpServletRequest
request) {
        ActionErrors errors = new ActionErrors();
        // For this form, only a username is required
            if( userName == null || userName.length()==0 ){
            errors.add("userName",new
ActionError("error.userName.required"));
        }
        return (errors);
    }



}

======Action======

package com.oreilly.actions;

import java.io.IOException;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.oreilly.forms.LoginForm;



/**
 * @struts:action       path="/login"
 *                      name="LoginAction"
 *                      scope="request"
 *                      input="/index.jsp"
 *                      validate="false"
 *                      redirect="false"
 * @struts:action-forward       name="success" 
path="/Welcome.jsp"     
 *                              redirect="false"
 * @struts:action-forward       name="failure"
path="/Login.jsp"
 *                              redirect="false"
 *
 * <strong>LoginAction</strong> demonstrates how an
action class is called within the struts framework
 * For the purposes of this sample, we simple
demonstrate how the perform is called,
 * a sample action, and a return
 * 
 [EMAIL PROTECTED] Sue Spielman Switchback Software LLC
www.switchbacksoftware.com
 */
public class LoginAction extends AbstStrutsActionBase 
{
    /**
     * Black box method used to authenticate a user.
There would typically
     * be a bean (or EJB) here that actually does the
work.
     * A lookup would be done (as shown in the base
class) and create on the home interface
     * to authenticate the user against some backend
database.
     [EMAIL PROTECTED] String containing username
     [EMAIL PROTECTED] String containing password
     [EMAIL PROTECTED] boolean - true authenticated, false not
authenticated.
     */
    public boolean authenticate(String username,
String password) 
    {
        // Do the appropriate lookup and calls. 
        // That code is not provided as part of this
sample.
        // Instead, it is just to demonstrate the
interaction
        // of the action class with business logic
tier.
        return(true);
    }

    /**
     * Override base class with specific
<strong>perform</strong> implementation
     * for this class.
     * @param mapping The ActionMapping used to select
this instance
     * @param actionForm The optional
AbstActionFormBase bean for this request (if any)
     * @param request The HTTP request we are
processing
     * @param response The HTTP response we are
creating
     * @exception IOException if an input/output error
occurs
     * @exception ServletException if a servlet
exception occurs
     */
    public ActionForward perform(ActionMapping
mapping, ActionForm form,
        HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException 
    {
        // Assume that the login fails, so that the
login page is redisplayed
        // if the user isn't authenticated
        boolean validLogin=false;
        ActionForward actionForward =
mapping.findForward(LOGIN);
        // Create the container for any errors that
occur
        ActionErrors errors = new ActionErrors();
        
        // Extract attributes and parameters we will
need from the incoming
        // form.
        LoginForm loginForm = (LoginForm) form;
        String userName = null;
        String password = null;
        if (loginForm != null){
            userName = loginForm.getUserName();
            password = loginForm.getPassword();
            validLogin = authenticate(userName,
password);
        }
        if (validLogin){
            // Forward control to the specified
'success' URI specified in the structs-config.xml
            actionForward =
mapping.findForward(SUCCESS);
            // Save something into the session for
later use.
           
request.getSession(true).setAttribute("USERNAME",
userName);
            
            
        } else  {
            errors.add("login", new
ActionError("error.login.authenticate"));
        }
        // If any messages is required, save the
specified error messages keys
        // into the HTTP request for use by the
<struts:errors> tag.
        if (!errors.empty()) {
            saveErrors(request, errors);
        }

        // Forward control to the appropriate URI as
determined by the action.
        return (actionForward);
    }
        

}



-----------------------------------------------------------------
每天都 Yahoo!奇摩
海的顏色、風的氣息、愛你的溫度,盡在信紙底圖
http://tw.promo.yahoo.com/mail_premium/stationery.html

Attachment: sample.zip
Description: sample.zip

Reply via email to