Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 50
Understanding websocket example in spring 1 54
why cannot we forward request once the response is committed 2 33
Windows 10 IE Certificate Issue 10 41
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)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

937 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

4 Experts available now in Live!

Get 1:1 Help Now