Wow, that's much cleaner! Thanks for sharing. I plan on putting all my code
on-line for other beginners in the next few weeks. I think I've got enough
with my beans, servlets, and jsps to do a little tutorial. The kind of thing I
wish I had had when I started out :)
Thanks again,
Scott
Lance Lavandowska wrote:
> Scott,
>
> you're approach was correct. I rewrote your code to improve readability
> a little bit ) and it worked fine.
> I'll include my modified code below my sig for your review.
>
> Lance Lavandowska
> Software Engineer
> http://www.AgDomain.Com
>
> <% //code to create drop down list of states... and select one of
> String[] statea =
> {"AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID",
> "IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO",
> "MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA",
> "PR","RI","SC","SD","TX","TN","UT","VT","VI","VA","WA","WV","WI", "WY" };
>
> String[] statef =
> {"Alamaba","Alaska","Arizona","Arkansas","California*","Colorado",
> "Connecticut*","Delaware","District Of Columbia","Florida*","Georgia",
> "Hawaii","Idaho","Illinois*","Indiana","Iowa","Kansas","Kentucky","Louisia
> na","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi
> ", "Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey*",
> "New Mexico","New York*","North Carolina","North Dakota","Ohio*",
> "Oklahoma","Oregon","Pennsylvania*","Puerto Rico","Rhode Island", "South
> Carolina","South Dakota","Texas*","Tennessee","Utah","Vermont", "Virgin
> Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming"
> };
> %>
>
> <FORM Action=testState.jsp>
> <SELECT NAME="state">
> <%
> for (int i = 0; i < 53; i++)
> {
> String value = (String) statea[i];
> String name = (String) statef[i];
> String selected = "";
> //change the order for your "equals" and you won't have to worry about
> null pointers
> if (value.equals(request.getParameter("state")))
> {
> selected = " SELECTED";
>
> } else if ( value.equals("CA") ) { // CA is the default
> selected = " SELECTED";
>
> }
> %>
> <OPTION VALUE="<%=value%>"<%=selected%>><%=name%></OPTION>
> <%
> }
> %>
> </SELECT>
> <input type=submit>
> </form>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html