It's not a secret anymore!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Strutsnewbie" Watch "Strutsnewbie" New topic
Author

Strutsnewbie

sree_prasad
Greenhorn

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 login.do then
it goes directly to action class without showing the login.jsp page.
It then gives me null pointer exception.
------------------------------------------------------|||||||||
LOGIN.JSP
--------------

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

<center>
<table width="400" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<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>

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

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

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

</tr>
</table>
</td>
</tr>
</table>
</center>
</html:form>
<body>
</html:html>

LOGINACTION
-----------------
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");
}

}


}


STRUTCONFIG
--------------

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


FORMBEAN
----------------

<form-bean name="LOGINFORM"
type="LOGIN.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.
sree_prasad
Greenhorn

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 login.do
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 "LOGIN-PREPARE.do" as the URL.


Merrill
Consultant, Sima Solutions
 
Don't get me started about those stupid light bulbs.
 
subject: Strutsnewbie
 
Similar Threads
exception in uploading the file
Kindly help me in fixing the bug . error 404
Struts Flow
I am unable to resolve the exception
Struts Error