Results 1 to 7 of 7
Thread: Generics problem in JSP?
- 07-25-2011, 09:19 AM #1
Generics problem in JSP?
Hi,
Java Code:List<Man> list=new ArrayList<Man>(); Man raja=new Man("Raja",25); Man pandian=new Man("pandian",23); Iterator<Man> ite=list.iterator(); while(ite.hasNext()){ Man obj=ite.next(); System.out.println(obj); }
The above code does work too good in my servlet. But in JSP its throws NullPointerException.
Does any one know why this happens in JSP ?Mak
(Living @ Virtual World)
- 07-25-2011, 10:30 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because you shouldn't be using scriptlets?
I don't know that scriptlets even allow 1.5 or later syntax (yet another reason not to use them).
- 07-25-2011, 11:03 AM #3
Hi,
FYI, I have put my code inside the scriptlets. One more thing I have to say here is that if I did not use generics in Iterator, It s works pretty well.
The above code works well in JSP..Java Code:List<Man> list=new ArrayList<Man>(); Man raja=new Man("Raja",25); Man pandian=new Man("pandian",23); Iterator ite=list.iterator(); while(ite.hasNext()){ Man obj=(Man)ite.next(); System.out.println(obj); }Mak
(Living @ Virtual World)
- 07-25-2011, 11:07 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Which is exactly what I said you should not be doing. Do not use scriptlets they are no longer recommended. That was one of the first ways of getting "dynamic" content in a JSP, and was quickly gotten rid of. It is only supported for backwards compatability (and you don't want to be backwards, do you?).
And did I not also just say that I don't believe 1.5 syntax (i.e. Generics, the new for "each" loop, etc) is supported in Scriptlets?One more thing I have to say here is that if I did not use generics in Iterator, It s works pretty well.
The above code works well in JSP..Java Code:List<Man> list=new ArrayList<Man>(); Man raja=new Man("Raja",25); Man pandian=new Man("pandian",23); Iterator ite=list.iterator(); while(ite.hasNext()){ Man obj=(Man)ite.next(); System.out.println(obj); }
Edit: Or maybe you're just using an out of date container that doesn't support 1.5.Last edited by masijade; 07-25-2011 at 11:10 AM. Reason: additional content
- 07-25-2011, 11:15 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Nope, afaik (and my knowledge may be outdated as well), the type parameters <T> in generic classes confuse the JSP compiler (they look too much like html tags), that's why JSPs only support Java up to version 1.4 (or no generics in later versions). imho, that entire http technology (and all of its paraphernalia) sucks big times.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-25-2011, 12:17 PM #6
The conclution of this Thread is: The type parameters <T> in generic classes confuse the JSP compiler. that's why JSPs only support Java up to version 1.4.
If any one of you has any objection in this conclusion, We can continue. Otherwise I will mark this as SOLVED.Mak
(Living @ Virtual World)
- 07-25-2011, 01:19 PM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
Problem with Generics and BinaryTree
By conderol in forum New To JavaReplies: 2Last Post: 04-28-2011, 08:09 AM -
generics
By arik23 in forum New To JavaReplies: 2Last Post: 04-21-2011, 04:28 PM -
Generics Problem (Bound Mismatch)
By castiel in forum New To JavaReplies: 2Last Post: 02-16-2011, 12:05 AM -
Generics problem
By ankur.trapasiya in forum New To JavaReplies: 2Last Post: 01-22-2011, 05:09 PM -
Help with generics
By shai in forum New To JavaReplies: 0Last Post: 08-12-2010, 07:07 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks