File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Strutsnewbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Strutsnewbie" Watch "Strutsnewbie" New topic



Joined: Nov 21, 2007
Posts: 8
Could you kindly help me regarding this issue.

I have a login jsp which accepts username and password.
The login.jsp feeds a bean. The action class takes values from the bean and if
password is equal to " password " it goes to Success.jsp through action forward.

My issue is when I call the page i.e then
it goes directly to action class without showing the login.jsp page.
It then gives me null pointer exception.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<body bgcolor="white">
<html:form action="/login" method="post" ;">

<table width="400" border="1" align="center" cellpadding="0" cellspacing="0">
<table border="0" cellspacing="2" cellpadding="1" width="100%" >
<tr bgcolor="#eaeac8">
<td align="left" colspan="2"><font size="5">User Login</font></td>

<tr><td colspan="2"><p> </p></td></tr>

<tr align="center">
<td align="right">User ID:</td>
<td><html:text property="username" size="30" maxlength="30"/></td>

<tr align="center">
<td align="right">Password:</td>
<td><html assword property="password" size="30" maxlength="30"/></td>
<tr><td colspan="2"><p> </p></td></tr>

<TD>Login Now !<html:submit property="submit" value="Submit" /></TD>


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LOGINACTION extends {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

LOGINFORM loginform = (LOGINFORM) form;

if (loginform.getPassword().equals("password")
&& (loginform.getPassword() != null)) {

ActionForward forward = null;

return mapping.findForward("success");

else {

return mapping.findForward("failure");




<action path="/LOGIN"
type="COM.LOGINACTION"name="LOGINFORM" scope="request" validate="true"
<forward name="success" path="/jsps/LOGIN/Success.jsp" />
<forward name="success" path="/jsps/LOGIN/Failture.jsp" />


<form-bean name="LOGINFORM"

Any help would be greatly appreciated.
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
if (loginform.getPassword().equals("password")
&& (loginform.getPassword() != null)) {

Change to

if(null!=loginform.getPassword() && (("password").equals(loginform.getPassword())))

Hope you have identified the error.

Joined: Nov 21, 2007
Posts: 8
Thanks a lot for your help.
But my LOGIN.JSP is not getting loaded when I call the page i.e
so it is taking default values of password which is null and is getting fowarded to " faliture.jsp "
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The login action you have coded should be called only when the login.jsp form is submitted. To display the login.jsp page initially, I'd recommend creating a separate action. If you don't need any processing prior to displaying the JSP, just create a forward action. Example:

You would then invode "" as the URL.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Strutsnewbie
It's not a secret anymore!