Hi,
I have a
JSP form that I post to a controller
servlet. I would like the form to automatically populate a
java bean so that the controller servlet can then extract the data from the bean.
I read somewhere that the following will do that:
<jsp:useBean id="fBean" class="com.djwheatley.FormBean" scope="session">
<jsp:setProperty name="fBean" property="*"/>
</jsp:useBean>
<form action="Controller" method="post">
Username: <input type="text" name="username"/> <br/>
Password: <input type="text" name="password"/> <br/>
<input type="hidden" name="action" value="login"/>
<input type="submit" name="submit" value="OK"/>
</form>
My "FormBean" class is as follows:
public class FormBean
{
private StringsUsername;
private StringsPassword;
private StringsAction;
/*
* Default constructor
*/
public FormBean()
{
sUsername = "";
sPassword = "";
sAction = "";
}
public void setUsername(
String user)
{
sUsername = user;
}
public String getUsername()
{
return sUsername;
}
public void setPassword(String p)
{
sPassword = p;
}
public String getPassword()
{
return sPassword;
}
public void setAction(String a)
{
sAction = a;
}
public String getAction()
{
return sAction;
}
}
Then in my Controller class I have:
public void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
FormBean fBean = (FormBean)request.getAttribute("fBean");
BUT fBean is always NULL.
Any ideas? Is this actually possible, or am I confused?
Thanks
Darren.