Introspection is used with beans, that is correct. You should really create
a Bean for each type of Form a user could submit into the system. Then using
Introspection & the HttpServletRequest you could iterate through all the
form properties and the introspection would call the get/set methods of that
bean to pass through the values passed into the Servlet.

The name of the input fields on the form should be the same as the
attributes in the bean.

..example..

<form name="UserLogin" action="UserLogin.do" method="post">
<input type="text" name="username">
<input type="text" name="userpassword">
</form>

the corresponding bean should be


public class UserBean {

private String username;
private String userpassword;

public UserBean(String username, String userpassword) {
        this.username = (( username == null ) ? "" : username);
        this.userpassword = (( userpassword == null ) ? "" : userpassword );
}

public UserBean() {}

public String getUsername() {
        return this.username;
}

public void setUsername(String username) {
        this.username = (( username == null ) ? "" : username );
}

public String getUserpassword() {
        return this.userpassword;
}

public void setUserpassword(String userpassword) {
        this.userpassword = (( userpassword == null ) ? "" : userpassword );
}

}


This code is not tested, but should give you the idea of what I mean. Again,
I strongly recommend you look into Model 2.

Hope this helps, Dean.

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet API
Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Silvia Gaspar
Sent: Friday, August 18, 2000 9:54 AM
To: [EMAIL PROTECTED]
Subject: Re: Null Values in Servlets

I went to javasoft site and it seems to me that introspection its more used
in Beans. Can I also use that in servlets? How?

Com os nossos melhores cumprimentos,
----------------------------------------------------------------------------
-------------------------------
Compta - Equipamentos e Servi�os de inform�tica, S.A

S�lvia Gaspar
Engenharia de Sistemas e Aplica��es
Implementa��o
Consultora  S�nior
?  TEL: +351.21. 350 14 00
?  Directo:     +351.21. 313 55 51
?    Fax:       +351.21.352 02 02
??e-mail:    [EMAIL PROTECTED]
? WWW:      www.compta.pt

 -----Original Message-----
From:   Dean Sheppard [mailto:[EMAIL PROTECTED]]
Sent:   sexta-feira, 18 de Agosto de 2000 14:30
To:     [EMAIL PROTECTED]
Subject:        Re: Null Values in Servlets

Use introspection to capture all valid .getParameters(), then the bean
associated to the form can simply check for null values when assigning them


Ie...

        public void setUserName(String username) {
                this.username = (( username==null)? "" : username );
        }

This should alleviate the null value problems. If you are not familiar with
introspection I would recommend reading about it on the javasoft site. It
would help if you were implementing your JSP/Servlets using the Model 2
architecture as well.

Hope this helps... Dean


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet API
Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Silvia Gaspar
Sent: Friday, August 18, 2000 8:58 AM
To: [EMAIL PROTECTED]
Subject: Null Values in Servlets
Importance: High

        This data comes from a form and its pass to the servlet when we
press the submit button, so I don't have any type of control over that. If
the user don't write nothing, the field will have the null value in the
servlet.

Com os nossos melhores cumprimentos,
----------------------------------------------------------------------------
-------------------------------
Compta - Equipamentos e Servi�os de inform�tica, S.A

S�lvia Gaspar
Engenharia de Sistemas e Aplica��es
Implementa��o
Consultora  S�nior
?  TEL: +351.21. 350 14 00
?  Directo:     +351.21. 313 55 51
?    Fax:       +351.21.352 02 02
??e-mail:    [EMAIL PROTECTED]
? WWW:      www.compta.pt

-----Original Message-----
From:   Girish K [mailto:[EMAIL PROTECTED]]
Sent:   sexta-feira, 18 de Agosto de 2000 12:34
To:     [EMAIL PROTECTED]
Subject:

One option is to use "" instead of sending empty values. Invariably, from
what I have noticed, these are 'null' values. If not set, then this causes
an error.
I hope this helps,
Girish

___________________________________________________________________________
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

___________________________________________________________________________
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

___________________________________________________________________________
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

___________________________________________________________________________
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

___________________________________________________________________________
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