Check Java Man's previous post.
This code :
if ((name == null) || (name.trim()==""))
won't work. Specifically, you shouldn't compare Strings with ==. A better
solution would be
if (param == null || "".equals(param.trim())) {
"SELECT * FROM name";
}
else {
sqlstr ="SELECT * FROM name WHERE fname LIKE '"+param + "'";
}
Another note to the original poster is that param is not being checked to
make sure it contains the '%' wildcard characters. The second query might
be changed to
sqlstr ="SELECT * FROM name WHERE fname LIKE '"%" + param + "%'";
if that is the case, param should be stripped of all '%' characters.
Regards,
Richard
At 03:16 PM 11/28/2001 -0500, you wrote:
>Kwan,
>
>Your string could be all blanks.
>
>try testing like:
>
>String name = request.getParameter ("name");
>if ((name == null) || (name.trim()==""))
>
>--amrinder
>
>_____________________________________________
>From: Kwan, William [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, November 28, 2001 2:54 PM
>To: [EMAIL PROTECTED]
>Subject: checking value of parameter from jsp
>
>
>Hi all,
>
>I'm passing information from a html page to a servlet.
>
>Here is some code:
>
>String param = request.getParameter("name");
>if (param == null) sqlstr = "Select * from name";
>else sqlstr ="Select * from name where fname like '"+param + "'";
>
>and
>
>if (param == "") sqlstr = "Select * from name";
>else sqlstr ="Select * from name where fname like '"+param + "'";
>
>These both dont detect the blank value when they click submit on the jsp
>page. It always goes to the else part.
>
>Am I doing something wrong?? Is there another way to detect if they entered
>any data in the field on the form??
>
>thanks,
>Will
>
>___________________________________________________________________________
>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