aspose file tools*
The moose likes Servlets and the fly likes Problem using StringArray Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem using StringArray" Watch "Problem using StringArray" New topic
Author

Problem using StringArray

L.John
Greenhorn

Joined: Aug 29, 2001
Posts: 24
Dear all,
I wanted to clear this doubt. It would be kind if anyone could help me with this doubt.
====This is the html part==========
<TR><TD>domain name </TD><TD><input name="dname"></TD></TR>
<TR><TD>nameserver 1</TD><TD><input name="nameserver"></TD></TR>
<TR><TD>nameserver 2</TD><TD><input name="nameserver"></TD></TR>
<TR><TD><input type="submit" value="redelegate domain"></TD></TR>
<input type="hidden" name="command" value="REDELDOMAIN">
====This is the servlet part========
String domainname = request.getParameter("dname");
String command = request.getParameter("command");
String nameServersA[] = request.getParameterValues ("nameserver");

if (command.equalsIgnoreCase("REDELDOMAIN")) {
domainRed(domainname, nameServersA);
}
public void domainRed(String domainame,String name_serversA[] {

if (domainname == null || domainname.length() == 0 {
out.println(" name is empty ");
return;
}else if(name_serversA == null || name_serversA.length
== 0 ){
out.println("No nameServers provided ");
return;
}
Now here even if i dont give any nameservers in the html form still the above message is not printed . then to test it, I did the following:
System.out.println(" name_serversA = " + name_serversA + " name_serversA[] = " + name_serversA.length);
the output is :::::: name_serversA = [Ljava.lang.String;@fbdc74d6
and name_serversA[] = 4
WHY?
If i have not entered any values for nameserver then i want to return the page back to the user to provide the nameservers .
Kindly let me know how can this be done.
Many Thanks
Kind Regards,
L.John
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
You are going to get an array of empty strings, not a zero-length array.
Les Dsouza
Greenhorn

Joined: Jan 29, 2002
Posts: 27
Yes,
getParameterValues returns null only if the named parameter does not exist.
So even if the user does not enter anything , empty strings will be sent to the servlet.
L.John
Greenhorn

Joined: Aug 29, 2001
Posts: 24
Thanking for reply.
yes its true that it will never be null in this case. It can only if the named parameter does not exists.
How could i proceed further and validate the textbox then. I mean , if the user leaves the nameserver text box blank , then i would like to return it back to the user with a out.println statement .
Kindly let me know about it.
Many Thanks
Kind Regards,
L.John
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
In your code check for one more condition i.e, check stringname.equals("") which returns true or false. Make use of this boolean in your program.
One more solution would be if text feild are mandatory then use javascript to validate the same at the client side itself.
-arun
[ January 31, 2002: Message edited by: arun boraiah ]

Sharing is learning
L.John
Greenhorn

Joined: Aug 29, 2001
Posts: 24
Thanking all who have replied back to my query.
Hi Arun,
Thanks for replying back to me .
Asu advised i have changed the condition here :
if (name_serversA_IP[i] != null && !name_serversA_IP[i].equals(""))
using this would indeed be a better way.
Thanks once again for your valued solution.
Kind Regards
L.John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using StringArray