aspose file tools*
The moose likes Struts and the fly likes  am not able to set the value in my ActionForm class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark " am not able to set the value in my ActionForm class" Watch " am not able to set the value in my ActionForm class" New topic
Author

am not able to set the value in my ActionForm class

Sharadji Kumar
Greenhorn

Joined: Feb 24, 2013
Posts: 1
hi ,
i have just trying a simple example in struts .
i am not able to set the value in my ActionForm class and that why i am getting null value in my Action class
below is my code

Login.html
=====================================================

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<form action="LoginPage.do" >
Login Page
User Name: <input type="text" name="userName">
Password : <input type="password" name="pwd">
<input type="submit" value="Login" align="middle"> SingUp

</form>
</body>
</html>

LoginAction Class

package com.sharad.login;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
{
LoginForm loginForm=(LoginForm)form;
String uname=loginForm.getUserName();
String pwd=loginForm.getPwd();
if(uname == null || uname.equals(""))
{ System.out.println("username"+uname+"pwd"+pwd);
return (mapping.findForward("bad-email"));
}
else if(pwd == null || pwd.equals(""))
{ System.out.println("pass");
return (mapping.findForward("bad-pass"));
}
else
{ System.out.println("good to go");
return (mapping.findForward("success"));
}

//return null;

}
}

LoginForm

package com.sharad.login;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm
{
private String userName ;//="Please enter UserName";
private String pwd;//="Please enter Password";
public String getUserName()
{
System.out.println("get uname"+userName);
return userName;
}
public void setUserName(String userName) {
System.out.println("set"+userName);
this.userName = userName;
}
public String getPwd() {
System.out.println("get pwd"+pwd);

return pwd;
}
public void setPwd(String pwd) {
System.out.println("set pwd"+pwd);
this.pwd = pwd;
}

}

struts-config.xml



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
<form-beans>
<form-bean name="skm"
type="com.sharad.login.LoginForm" />

</form-beans>
<action-mappings>
<action name="skm"
path="/LoginPage"
type="com.sharad.login.LoginAction"
scope="request" >

<forward name="bad-email" path="/WEB-INF/results/email.jsp"/>
<forward name="bad-pass" path="/WEB-INF/results/pass.jsp"/>
<forward name="success" path="/WEB-INF/results/confirm.jsp"/>
</action>
</action-mappings>
</struts-config>

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: am not able to set the value in my ActionForm class
 
Similar Threads
NullPointerException, can not able to access ActionForm data inside execute() metod of Action class
problem in Developing Struts small Apllication
ServletException in:/pages/logon.jsp] Cannot retrieve definition for form bean null'
Problem with a simple struts application
blank page - Action is not called