Solved

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

Posted on 2001-06-21
4
174 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now