• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem using StringArray

 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are going to get an array of empty strings, not a zero-length array.
 
Les Dsouza
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
L.John
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic