• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

am not able to set the value in my ActionForm class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>

 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic