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

Retreiving string values

Tim Wild

Joined: Jun 10, 2002
Posts: 3
I am using the following code to retrieve data in a HTTP request
Enumeration names;

names = request.getParameterNames();
if ((names != null) && (names.hasMoreElements())) {
while (names.hasMoreElements()) {
String name = (String) names.nextElement(); //get the value of the next element, cast it to a string

String values[] = request.getParameterValues(name);
for (int i = 0; i < values.length; i++){String title = XMLencode(values[i]);}
How do I retreive the value of the String title to display in the page?
Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
I didn't test this but you'll definitely need to move your declaration of "title" from the scope of the loop:

Hope that helps!
Tim Wild

Joined: Jun 10, 2002
Posts: 3
Thanks but I'm still getting errors
Is the following sufficient to instantiate the variable, does it not need a default value?

Is it possible to assign a value to the variable from within a method. I've read about instance variables etc but confess to not fully understanding it.

Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
if it is declared within a method, it will need to be given an initial value. The compiler will not even allow it.

So much trouble in the world -- Bob Marley
It is sorta covered in the JavaRanch Style Guide.
subject: Retreiving string values