Solved

Don't think this is possible... but-  dynamic variable declarations in JSP- ???

Posted on 2001-06-21
4
176 Views
Last Modified: 2010-03-31
JSP question

I have an array that is made up of the names of all my form fields of the calling page.  In the current page I break apart the array into the individual field names.

I then want to in a for loop, declare String variables with the same name as the fields in the array-

// quick attempt at explaining what I'm talking about
String ArrayVal = "Color,Qty,Cost"; //actually passed in String temp = "";
for(int i=0;i<ArrayVal.length();i++){
   // extract each field name using charAt and substring
   temp = ArrayVal.substring(startPos, i);
   // I need to code it like this:
   String temp = request.getParameter(temp);
   //but I actually need it to function like this:
   // String Color = request.getParameter("Color");
}

The problem is that the prior form is dynamically built, so I'll never know which fields will be there...  

open to any suggestions.

Thanks
0
Comment
Question by:brian_s
4 Comments
 
LVL 2

Expert Comment

by:venkat2000120699
ID: 6215860
I think it is not possible to do like that.  You can use a Hashtable for that purpose.

U can store the field names of the html form as indexing fields and the values corresponding to them as the values in Hashtable.

eg;

"color"   "blue"
"height"  "20"
"width"   "30"
0
 
LVL 2

Accepted Solution

by:
vpadma earned 100 total points
ID: 6216007
Why dont you try StringTokenizer to break the fields instead of looping through in the string.
I actually dont understand what your question exactly is. Are you having trouble in breaking up these array values or somewhere else?

Padma.
0
 

Author Comment

by:brian_s
ID: 6217992
I can break them up just fine, but I want to define variables for each of them in my JSP.  

But I can't just setup static variable declarations, b/c the fields getting passed in will always be different.

For every product that we have a different form form will be created, all throught the same JSP though:

my JSP- DrawWksht.jsp will generate a form with different variables depending on if the product is say a CD or a CD-R....etc.

so different form fields will be getting passed to my CostLookup.jsp every time.  I'll never know ahead of time which fields are coming in to my CostLookup-

does this help to clarify...?

probably not..huh?  It's hard for me to explain-
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6220372
Hi,

How are you going to use variables you trying to declare? Thing you askung for is not possible in JSP, and I belive is not useful either. Do you have some perl background? Welcome to the world of copiled languages!

Regards,
Igor Bazarny,
Brainbench MVP for Java 1
www.brainbench.com
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 59
print map entry 34 69
ForLoop Example 3 48
How to determine if a string is a valid SHA value 7 32
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question