File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes name/value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "name/value" Watch "name/value" New topic


Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
What is the best way to populate a form from a name/value pair that is stored in a text file?

the data would look like this:
Also, can I use a dash as the delimiter?

Thank you.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
Oddly enough, Iain Emsley has the same problem on another posting on this very same board. He is using a regular expression and the split method of String.
Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
I just realized that this should have been posted in the JSP forum. Is there anyone that can move it over for me? I don't want to double post.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Consider "Wilkes-Barre-Pennsylvania"...
Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
I would consider it if Wilkes-Barre were the capital of PA.
Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192
I guess maybe I should explain what I wanna do then someone might be able to tell me if it can even be done in jsp.

I have a jsp form that contains a drop-down list of all the states. When the user chooses a state, I want the capital field in the form to get populated with the chosen state's capital city. I have the state/capital pairs in a text field with a dash as the delimiter.

Any ideas would be appreciated. Thank you.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I am assuming you meant text file above. You can read that into a collection such as a map. The StringTokenizer can be helpful there. Then when a state is selected, you can call a method on the backend that will return the state's capital.

So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Be sure not to do this in the JSP itself. In fact, if the text file is not going to change much, load it into a Map in application scope at application startup.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: name/value
It's not a secret anymore!