Hey there working on learning jsp. I have this code that takes CSVs from a text area and right now seperates then by commas and \n then prints it out. Where I'm stuck is that I need to either put all the values into an array and be able to check every other value or put evey other value into a seperate array (not sure which would make more sense). So i guess the big thing is I can seperate the value and print them but I'm just not understanding how to put them into an array. Any help or pointing in the right direction is much appreciated.
I don't understand your question. You seem to be aware of two different options to achieve what you want, so where are you stuck? Did you try either or both of them? Were you unable to make them work?
If you're having difficulty, provide an SSCCE (a simple standalone Java app that shows this problem, since it has nothing whatsoever to do with JSPs) and indicate clearly where you're having trouble.
I will point out, however, that just taking a slightly educated guess at what you're trying to do, it looks like both your approaches are icky.
You have something like this, I assume:
That is, for example, a multiline string of product names and prices. And you're looking to do something like one of the following:
[Hamburger, 3.50, Cheeseburger, 4.00, ...]
[Hamburger, Cheeseburger, ...], [3.50, 4.00, ...]
[Hamburger, ..., Cup-o-java, 3.50, ..., 1.50]
That is, put all the data in one array, alternating product name and product price, or two arrays, one for names and one for prices, or one array with all the names followed by all the prices.
If this is the case, then don't do it. Unless you're immediately feeding the resulting arrays to some other code that expects the data to be in that form and that you can't change to take it in some other way, it will just cause you headaches, and it defeats part of the purpose of using an OO language--encapsulation.
You want to define a class, say, Product, with fields for the name and price. For each line, create a Product instance, and fill in its data with the values from the line. You then have a single array of Products. Or, if you are familiar with or ready to learn Collections, use a List<Product>.
Or am I totally off base with regard to your problem?
No you are correct. What I want to do is then feed it into a secondary hidden form of a different layout. So basically I want to take these values and put them into seperate text boxes. I know it sounds odd but it seems the best solution to my current problem.
So it would be something like: <input type="hidden" name="prod1" value="hamburger"><input type="hidden" name="price1" value="3.00">...
So maybe the whole array idea isn't even the way to go. I guess my real problem is I can print the data out into one long string but I'm not entirely sure how to go about seperating it out into the seperate pieces.
I still don't know what you're actually trying to accomplish or what difficulty you're having. Please provide an SSCCE that shows your best attempt. A comment is fine if you're absolutely flummoxed on what to do at some step. Also indicate clearly what you'd like the final result of executing the code to look like.
Your question has nothing to do with JSP. You shouldn't even put that code in a JSP in a first place. I asked you to show your code in a non-JSP SSCCE. You also need to indicate clearly what you'd like the end result to be. You've been told all this already. I'm sorry, but I'm not interested in looking at Java code that's in a JSP that shouldn't be, and if you ignore my requests to make it easier for me to understand your problem, I feel I'm wasting my time trying to help. I'll bow out now.