•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,184 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,660 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1272 | Replies: 4
![]() |
| |
•
•
Join Date: Nov 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
hey guys,
I'm realtively new to jsp, and I want to create java objects and use them later in the jsp code.
Here's what I do:
However, I get errors of the sort:
I'm realtively new to jsp, and I want to create java objects and use them later in the jsp code.
Here's what I do:
<%!
public static java.util.List attrTypesArray = new java.util.ArrayList(50);
public static boolean myBool;
attrTypesArray.add("aaaa");
pageContext.setAttribute("attrTypesArray", attrTypesArray);
pageContext.setAttribute("myBool", myBool);
myBool = attrTypesArray.contains("aaaa");
%>
<c:out value='${myBool}'/>However, I get errors of the sort:
Unable to compile class for JSP: An error occurred at line: 65 in the jsp file: /file.jsp Syntax error on token(s), misplaced construct(s)
•
•
Join Date: Nov 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
hey, you are right abut the declaration tags. However the problem seems to be different - I cannot mix jsp and jstl tags (particularly, I cannot use the myBool variable in the c:out tag)
Therefore I still need your help. I have to go through the elements of a collection (preferably using jstl <c:forEach>) but for each element I want to check whether I have already passed through another one with the same attribute_1. If yes, then I print it's attribute_2, if not - I print both attributes.
So, obviously I need to keep track whether another element with the same attribute_1 has been already checked in the "forEach" loop. Hence, I think I should use a container like ArrayList or something similar to check whether myArrayList.contains(myAttribute_1).
Is there a way to keep track of these attributes in jstl, or I should use pure jsp ?!?
... or can I create the ArrayList in jsp and then somehow use it within the jstl <c:forEach> tag?
maybe my problem description is a littel confusing - sorry - just ask if you don't understand something.

Pesho
Therefore I still need your help. I have to go through the elements of a collection (preferably using jstl <c:forEach>) but for each element I want to check whether I have already passed through another one with the same attribute_1. If yes, then I print it's attribute_2, if not - I print both attributes.
So, obviously I need to keep track whether another element with the same attribute_1 has been already checked in the "forEach" loop. Hence, I think I should use a container like ArrayList or something similar to check whether myArrayList.contains(myAttribute_1).
Is there a way to keep track of these attributes in jstl, or I should use pure jsp ?!?
... or can I create the ArrayList in jsp and then somehow use it within the jstl <c:forEach> tag?
maybe my problem description is a littel confusing - sorry - just ask if you don't understand something.

Pesho
Well, don't mix them. Eliminate the scriptlets altogether. You should be doing this stuff in Beans, and the like.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Nov 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
ok 
but what if in the JSP tags I want to use info passed by the servlet?
For instance, in my servlet I have the following:
Now in the jstl tags of myJSP.jsp I can use the following:
BUT I cannot use the following:
... it complains that myAnimal cannot be resolved
Could you please explain why I cannot use "myAnimal" in the plain JSP tags???
Thans a lot ! ! !

but what if in the JSP tags I want to use info passed by the servlet?
For instance, in my servlet I have the following:
Animal myAnimal = new Animal();
// Set attributes
request.setAttribute("myAnimal", myAnimal);
getServletContext().getRequestDispatcher("/myJSP.jsp").forward(request, response);Now in the jstl tags of myJSP.jsp I can use the following:
<c:forEach items='${myAnimal.body.legs}' var="leg">
......
</c:forEach>BUT I cannot use the following:
<% for(int i=0; i<myAnimal.getBody().getLegs().length; i++) { %>
......
<% } %>Could you please explain why I cannot use "myAnimal" in the plain JSP tags???
Thans a lot ! ! !
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
Similar Threads
- Simple array question (C++)
- Simple algorithm question/needed (Java)
- Play mp3 in jsp (JSP)
- Simple Class Question (C++)
- install and run tomcat3 and implement a simple jsp page (JSP)
- simple msn question (Windows Software)
- Simple (I think) Code Question (PHP)
Other Threads in the JSP Forum
- Previous Thread: witch one is better Jboss server or tomcat server
- Next Thread: HTML - .jsp?



Hybrid Mode