You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Tuan H. Le" <tu...@phsadc.com> on 2002/09/23 21:56:38 UTC

Newbie Question: Login form submit error - Servlet action is currently unavailable

Hi,

I'm trying to get the login functionality to work with Struts, but when I submit data from a login form (with empty user ID/password or witth data), I got an error

HTTP Status 503 - Servlet action is currently unavailable

Here're my struts-config.xml, login.jsp, LoginForm.java
1) struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
  <!-- <data-sources> element must be added prior to the <form-beans> and <action-mappings> -->
  <data-sources>
  </data-sources>

  <form-beans>
    <form-bean name="loginForm" type="com.phs.ezhr.forms.LoginForm" />
  </form-beans>

  <global-forwards>
    <forward   name="login"		path="/login.jsp"/>
    <forward   name="success"		path="/mainMenu.jsp"/>
  </global-forwards>

  <!-- Action Mapping Definitions -->
  <action-mappings>
    <!-- Process an employee login -->
    <action path="/Login"
            type="com.phs.ezhr.security.LoginAction"
            validate="true"
            input="login.jsp"
            name="loginForm"
            scope="session" >
    </action>
  </action-mappings>

  <controller contentType="text/html;charset=UTF-8" debug="3" locale="true" nocache="true" />

  <message-resources parameter="com.phs.ezhr.ApplicationResources" null="false" key="org.apache.struts.action.MESSAGE" />
</struts-config>


2) login.jsp
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
  <link rel="stylesheet" type="text/css" href="stylesheets/styleLogin.css">
  <head>
    <title><bean:message key="app.title" /></title>
  </head>

  <body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="images/logoBig.gif" width="202" height="48" hspace="8" vspace="8"></td>
        <td width="60%" valign="top" align="right">&nbsp;</td>
      </tr>
    </table>
    <table border="0" cellspacing="0" cellpadding="0" width="100%" style="background: url(images/topTile.gif) repeat-x;">
      <tr>
        <td><img src="images/loginTopLeft.gif" width="472" height="38"></td>
        <td><img src="images/loginTopRight.gif" width="155" height="38"></td>
      </tr>
    </table>
    <html:errors />
    <html:form action="/Login"
      name="loginForm"
      type="com.phs.ezhr.forms.LoginForm"
      method="GET"
      focus="employeeId" >
    <table height="240" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF">
      <tr>
        <td>
	  <table cellspacing="2" cellpadding="2" border="0">
            <tr>
              <td colspan="2" class="text" style="padding: 10px;"></td>
            </tr>
            <tr>
              <td class="label" valign="bottom" align="right"><b><bean:message key="app.employeeId" />:</b></td>
              <td><html:text property="employeeId" /></td>
            </tr>
            <tr>
              <td class="label" valign="bottom" align="right"><b><bean:message key="app.password" />:</b></td>
              <td><html:password property="password" /></td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
              <td colspan="2" align="center"><html:submit /></td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    </html:form>
  </body>
</html:html>

3) LoginForm.java
package com.phs.ezhr.forms;

/**
 * Title:
 * Description: It provides accessors to data members that map to the values
 * submitted by the Login View -- employee ID and password -- and it performs
 * some simple validation of those values.  If the values pass the validation,
 * then the transaction continues; otherwise, ActionErrors are created and the
 * request is forwarded back to the value defined by this Actions input
 * sub-element, which in this case is Login.jsp
 * Copyright:    Copyright (c) 2002
 * Company:      PacifiCare Health Systems - ADC
 * @author Tuan H. Le
 * @version 1.0
 */

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

/**
 * This ActionForm is used by the EZHR appliation to validate
 * that the user has entered an employee ID and a password. If one or
 * both of the fields are empty when validate is called by the
 * ActionServlet, error messages are created.
 */
public class LoginForm extends ActionForm {
  // The user's password
  private String password;

  // The user's access ID
  private String employeeId;
  /**
   * Default Constructor
   */
  public LoginForm() {
    super();
    resetFields();
  }

  /**
   * This method is called with every request.  It resets the
   * Form attribute prior to setting the values in the new
   * request.
   *
   * @param mapping The mapping used to select this instance
   * @param request The servlet request we are processing
   */
  public void reset( ActionMapping mapping,
                     HttpServletRequest request ) {

    // Clear out the access number and pin number fields
    resetFields();
  }

  /**
   * @param anEmployeeId The employee ID
   */
  public void setEmployeeId( String anEmployeeId ) {
    this.employeeId = anEmployeeId;
  }

  /**
  * @retrurn The employee ID
  */
  public String getEmployeeId() {
    return this.employeeId;
  }

  public void setPassword( String aPassword ) {
    this.password = aPassword;
  }

  /**
  * @retrurn The employee password
  */
  public String getPassword() {
    return this.password;
  }

  protected void resetFields() {
    this.employeeId = "";
    this.password = "";
  }

  /**
   * 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();

    // Check and see if the access number is missing
    if( employeeId == null || employeeId.length() == 0 ) {
      ActionError newError = new ActionError( "errors.employeeId.required" );
      errors.add( employeeId, newError );
    }

    // Check and see if the password is missing
    if( password == null || password.length() == 0 ) {
      ActionError newError = new ActionError( "errors.password.required" );
      errors.add( password, newError );
    }
    return errors;
  }
}


4) My environment:

Tomcat 4.1.10
Struts 1.1b2
Windows XP


I can provide web.xml and LoginAction.java if needed.

Much thanks in advance for your helps!

Tuan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Newbie Question: Login form submit error - Servlet action is currently unavailable

Posted by Eddie Bush <ek...@swbell.net>.
What did you have in your logs?  I believe something happened so that 
ActionServlet didn't load ... find the trace and you'll find your 
problem.  Of course, I could be wrong :-)

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>