• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array of Beans in JSP

 
Murugan Patham
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the follwoing code, when the user enters a userid, I'm calling the Servlet, which gets the detail and pass it back to same JSP in an array of Bean, type ClientUsers.

I get this error
/opt/bea/user_projects/extDev/extDevSvrC1/.wlnotdelete/extract/extDevSvrC1_OAT_OAT/jsp_servlet/__cuaccount.java:198: cannot resolve symbol
symbol : class userColl
location: class jsp_servlet.__cuaccount
userColl[] users = (userColl[])request.getAttribute("userColl"); //[ /CUaccount.jsp; Line: 101]
^
How can I declare this array userColl[] as ClientUsers[] type. Bear with me for this fundamental question.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The useBean tag is for those of us who don't want scriptlets in their JSPs.
Since you're doing everything with scriptlets anyway, don't bother with useBean.
It can't handle arrays the way you were using it anyway.

Try something like:
 
Murugan Patham
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for your reply. I'm new and trying different things. Please let me know where I can find more details about using Beans instead of Scriptlet. I want to use beans instead of Scriptlet.

I did research on various books, and some on Google. Maybe I'm not using the right combination of words for search.

Earlier I used one of your examples for MVC and that was so helpful and was so easy to understand.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some really nice tools (EL and JSTL) if your using a JSP 2.0 compliant container.

Try Googling with the keywords: SCRIPTLESS JSP and you will find quite a few articles. In my second page of examples http://simple.souther.us/not-so-simple.html there is a project called SessionMonitor. In it there is a JSP that does something very similar to what you are doing with your scriptlet. The page monitor.jsp uses JSTL and EL to iterate over an arrayList of beans and print the contents as an HTML Table.

Our esteemed moderator Bear Bibeault is a very strong advocate of scriptless JSPs and quite the Guru on the subject. He may have some good resource links for you.

The one thing I would try to avoid is mixing scriptlets with any of the mechanisms that are designed to eliminate them. If you are going to go scriptless, do it all the way (either with the older xml syntax or with JSTL and EL). If not, adding JSTL, EL, and the XML syntax tools to your JSPs only obfuscates them.
One of the great strengths of Perl is the ability to write code in a variety of different syntactic styles. Perl's greatest weakness is that most of it's scripts are written in a variety of syntactic styles. It is now known as a "write-only" language because nobody can read anyone else's code. If we're not careful JSP is going to head down that same road.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!