Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jsp login check 12 43
jsp insert to database example 2 47
maven disable workspace resolution 1 22
java example issue 3 23
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

828 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