Hello,

This is killing me. I've got a form that posts to a servlet. I simply want
to get the form variables into a bean's properties.

I can find only one reference to what I'm trying to do here. it is a
formToBean() method from a FormUtils package, that some company sells.
Reading form variables into and out of javabean from a servlet has to be a
common activity. I can find heaps of info about using beans from JSP pages
(specifically about introspection), but I need to manipulate bean properties
from both Servlets and or JSPs. How do I do the introspection thing within a
servlet?




Code included below.


JSP Post to a Servlet. -> Servlet instantiates a FormBean ->
FormBean.validate() is called. -> but the validate() is always false because
the bean property vals are empty. Do I have to explicitly read each
request.getParameter("FORM_VAR") and set that to a bean property?

// from the servlet
//////////////////////////////////////////////
FormBean fb = new FormBean();
fb.setProperty(*); // ***** this aint workin - here *****
if (fb.validate()) {
        URL = "WELCOME";
} else {
        // go back
        URL = "INDEX";
}


// from FormBean
//////////////////////////////////////////////
private String UserName;
private String Password;

public boolean validate() {
        Debug.log (this, "validate","GETTING THIS FAR AT LEAST");

        boolean allOk=true;
        if (UserName.equals("")) {
                errors.put("UserName","Please enter a username");
                //UserName="";
                allOk=false;
        }
        if (Password.equals("") ) {
                        errors.put("Password","Please enter a valid
password");
                Password="";
                allOk=false;
        }
        return allOk;
}

public void setUserName(String uname) {
        UserName = uname;
}
public void setPassword(String pword) {
        Password =pword;
}

public String getUserName() {
        return UserName;
}
public String getPassword() {
        return Password;
}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to