File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Retreiving string values" Watch "Retreiving string values" New topic
Author

Retreiving string values

Tim Wild
Greenhorn

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

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

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
Greenhorn

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.

Thanks
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Retreiving string values
 
Similar Threads
JSP form submission problem
asp to jsp growing pains
Problem in Hash Table Output
Is this an array?
HttpServletRequest.getHeaders(aString)