aspose file tools*
The moose likes JSP and the fly likes JSTL : Retrieve Param Values Using Loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL : Retrieve Param Values Using Loop" Watch "JSTL : Retrieve Param Values Using Loop" New topic
Author

JSTL : Retrieve Param Values Using Loop

Darren Tay
Greenhorn

Joined: Jul 20, 2009
Posts: 5
Hi I have this problem that I have been trying to solve. I am also using Netbeans IDE 6.0.1

I have 2 pages "testing8-1" and "testing8-2"

In testing8-1.jsp, I have a forEach loop to generate a set of input text boxes.

In testing8-2.jsp, I have a forEach loop to produces the set of inputted data.

I have tried to retreive the data but find it impossible because I'm unable to do or do not know how to use the expression

In 'testing8-1.jsp'
'tier' is the name of the text box
my forEach loop uses tier${loop} to identify each textbox. The loop is from 1 to 10

In 'testing8-2.jsp'
My problem is that I am unable to retreive the data
The var loop is from 1 to 10
Methods I have tried:
${param.tier${loop}} -> impossible to use
${param.tier+loop} -> it generates the number instead
${param.tier and loop} -> it generates a false value
${param.tier && loop} -> it generates a false value

This is actually a testing page for my update sql:param value.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Did you look in the EL Specification to learn the proper expression syntax?

Hint: how would you index into an array if it were a Java expression?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Darren Tay
Greenhorn

Joined: Jul 20, 2009
Posts: 5
About the EL syntax, i think it has something to do with the . and the [] operator but I'm not sure. As for the java thing, I'm not sure myself. I'm still learning about JSTL with the use of beans. I think it has something to do with using a for loop to set the attribute and retreive variables with a request.getparameter?
Darren Tay
Greenhorn

Joined: Jul 20, 2009
Posts: 5
Sorry for the double post

um.... i think is something like this (i know its wrong though, please help me out here)

<%
String array[];
for (int i; i<10 ; i++){
String array="param.tier";
array[] = array[i];
}
%>
Roberto Hernandez
Ranch Hand

Joined: Apr 29, 2009
Posts: 33
Try something like this:
<c:forEach begin="1" end="10" items="${param.tier} var="tier" >
${tier}
</c:forEach>

I don't know if param.tier will work as a collection. If it doesn't, you could use something like ${requestScope.tier}. Give it a try
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Darren and Roberto, please be sure to use code tags when posting code.

Darren, what you posted is a scriptlet, and has nothing to do with the JSTL or EL. Scriptlets are to be avoided at all costs in modern web applications. Look, rather, at Roberto's solution.
Darren Tay
Greenhorn

Joined: Jul 20, 2009
Posts: 5
I'm sorry but using Roberto's solution did not work out, both the requestScope and the param.tier. I got blanks instead. I posted the codes so that you can better take a look at it.

The first page


The Second Page



Thanks for the aid
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Ummm, what's up with the forward:
<jsp:forward page="testing7-2.jsp"/>

in the middle of the form?

That's completely bizarre. What is your intention with that?

There are all manner of other problems with your code, but first things first.
Roberto Hernandez
Ranch Hand

Joined: Apr 29, 2009
Posts: 33
Try building a collection in your Servlet or Action


Now, in your JSP, add the forEach loop

Darren Tay
Greenhorn

Joined: Jul 20, 2009
Posts: 5
Thanks for the aid. I can now produce the result and can also apply it to my sql update.

The reason i am using an include is because i'm unable to use forward, this is actually unrelated to testing7-1 and 7-2, the reason I'm using this is because doing testing pages helps cut down errors. The flow for the orginal pages is something like this
(Snippits of the code)
Page 1


Page 2


Page 3


I think I might be running the risk of creating too much overheads, is there a better flow which you can recommend?
Also should I create a new thread for this qns?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSTL : Retrieve Param Values Using Loop