?
Solved

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

Posted on 2001-06-21
4
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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.
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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 …
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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