Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retreiving string values

 
Tim Wild
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

if(name.equals("orgConsTitle")){
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?
Thanks
 
Brian Glodde
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it is declared within a method, it will need to be given an initial value. The compiler will not even allow it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic