jQuery in Action, 3rd edition
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

am not able to set the value in my ActionForm class

Sharadji Kumar

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


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<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


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"));
{ System.out.println("good to go");
return (mapping.findForward("success"));

//return null;



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) {
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;



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

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"

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

<action name="skm"
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"/>

I agree. Here's the link: http://aspose.com/file-tools
subject: am not able to set the value in my ActionForm class
It's not a secret anymore!