wood burning stoves 2.0*
The moose likes Servlets and the fly likes   ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "  ..." Watch "  ..." New topic
Author

  ...

Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
Hi,
In posting a jsp (j1.jsp) to a servlet(s1.java), how do I detect the " " tag contained within a given parameter? For example, if the following html element is in j1.jsp, and the 3rd option (<OPTION>  29</OPTION> is selected:

<SELECT id=routePrefix name=routePrefix
style="HEIGHT: 22px; WIDTH:80px" >
<OPTION> </OPTION>
<OPTION>  00</OPTION>
<OPTION>  29</OPTION>
<OPTION>  53</OPTION>
<OPTION>  76</OPTION>
<OPTION>  FR</OPTION>
<OPTION>  IS</OPTION>
<OPTION>  SR</OPTION>
<OPTION>  US</OPTION>
</select>
when j1.jsp is posted, how to I detect the the " " token in request.getParameter("routePrefix")?
Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
my initial post actually shows the &"nbsp;" as " ", which illustrates my problem - I want to preserve the spaces on the HTML form, but space is ignored by the browser, so I have to use nbsp, but when posted, I don't know how to detect the nbsp found within the param...
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
In the jsp, just strip the space in front of the string 29 or in the servlet u can trim the string that u get out of the request
String xx = req.getParameter("routePrefix
").trim();
public String trim()
Removes white space from both ends of this string.
If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned.
AND if u get a "" after u trim, u know that the " " was selected.
HTH
[ May 20, 2002: Message edited by: sandy ind ]
[ May 20, 2002: Message edited by: sandy ind ]

Adios
Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
Thanks for the reponse, Sandy!
First of all, for my application, space is meaningful and critical in querying the correct data (ok. I didn't build the database). So I want to preserve the spaces around the options. Secondly, when my form is posted, the parameter obtained from the selection list, in our example, is not " 29" (space, space, 29), but something else; I have printed out the SQL from my servlet, copied it out to a SQLPlus session, run it, and it returns no resultset. If I deleted those 2 unknown characters and put in two spaces, my SQL would returns records as expected. So I think the "nbsp" is posted as something other than a space. Is there a way to evaluate the ascii value of a charater?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

Rather than spend time trying to figure out what comes back with nbsp, I would just do the following and be done with it.
<OPTION value="NONE"> </OPTION>
<OPTION> 00</OPTION>
<OPTION> 29</OPTION>
<OPTION> 53</OPTION>
<OPTION> 76</OPTION>
<OPTION> FR</OPTION>
<OPTION> IS</OPTION>
<OPTION> SR</OPTION>
<OPTION> US</OPTION>
------
Edit: OK, I re-read your question and the answer above doesn't do what you want. Was on the right track though. Again, what I would do is to just use the value attribute of the option tag like so:
<OPTION value=" "> </OPTION>
<OPTION value=" 00"> 00</OPTION>
<OPTION value=" 29"> 29</OPTION>
<OPTION value=" 53"> 53</OPTION>
<OPTION value=" 76"> 76</OPTION>
<OPTION value=" FR"> FR</OPTION>
<OPTION value=" IS"> IS</OPTION>
<OPTION value=" SR"> SR</OPTION>
<OPTION value=" US"> US</OPTION>
This allows you to display the spaces with nbsp and still get back regular spaces that will work with your db.
Junilu
[ May 21, 2002: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Gustavo Adolpho Bonesso
Ranch Hand

Joined: May 11, 2002
Posts: 103
You can use the following code :
System.out.println(Character.getNumericValue(req.getParameter("routePrefix").charAt(0)));
to get the chararacter at first position and show the Unicode value...
To get information about the Unicode Standart, visit :
http://www.unicode.org/
Best Regards !


Gustavo Adolpho Bonesso<br />SCJP1.4
Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
Gustavo,
Thanks for the reference to the unicode...
I took your suggestion did some test print, and my tests result as follows: Character.getNumericValue('A')=10
Character.getNumericValue('z')=35
Character.getNumericValue(' ')=-1
.
.
And then I looked at the code chart at the site you mentioned, and the codes for 'A', 'z', and ' ', respectively, are '0041', '007A', and '0020'. How are they converted?
Gustavo Adolpho Bonesso
Ranch Hand

Joined: May 11, 2002
Posts: 103
Vin,
You can use the hashCode() method to get a int value that represents, when converted to Hexadecimal, the same that you see in the Unicode Charts.
String test = " test";
Character A = new Character(test.charAt(0));
System.out.println("value: " + A.hashCode());
Integer i = new Integer(A.hashCode());
System.out.println(i.toHexString(A.hashCode()));
Best Regards !
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
I think Junilu Lacar is on the right track with his answer. You want to include a
'value' attribute in your OPTION elements. The contents of the value attribute will
be sent to your servlet (or JSP) when the page is submitted, even if the value contains
spaces.
Here is a technique I use to test these types of things (using IE)
First, save the file 'test.htm' as follows:

Now open it in IE (you don't need to open it through a web browser. Just use Windows
Explorer to navigate to the file, and double click on the file). Select the third element
from the drop-down list, then click 'Submit'. Now look at the address bar. You should see
a URL that looks like this:

You can see that the routePrefix parameter does not have any leading spaces.

Now replace the file with the following HTML code

Do the same thing (click on the 3rd choice in the drop-down list, the click Submit, and look
at the URL that appears in the address bar). Now the URL looks like this

The '+' is how a space looks in a URL parameter. In Java when you use .getParameter(), you
will see a space so .getParameter( "routePrefix") should retrieve " 29".
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
dear
go on track of junilu's solution...
that's the best bet.
good luck
Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
all,
Thanks for all the reponses! I have learned a great deal from this...
 
Don't get me started about those stupid light bulbs.
 
subject: &nbsp; ...