Results 1 to 7 of 7
  1. #1
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    431
    Rep Power
    6

    Default 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)

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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).

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    431
    Rep Power
    6

    Default

    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.

    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);			
    		}
    The above code works well in JSP..
    Mak
    (Living @ Virtual World)

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by makpandian View Post
    Hi,

    FYI, I have put my code inside the scriptlets.
    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?).
    One more thing I have to say here is that if I did not use generics in Iterator, It s works pretty well.

    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);			
    		}
    The above code works well in JSP..
    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?

    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

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    Edit: Or maybe you're just using an out of date container that doesn't support 1.5.
    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    431
    Rep Power
    6

    Default

    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)

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    No, the conclusion of this thread is that you should read the JEE 5 and/or JEE 6 tutorials, so that you can learn to do them right and not use scriptlets anymore.

Similar Threads

  1. Problem with Generics and BinaryTree
    By conderol in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 08:09 AM
  2. generics
    By arik23 in forum New To Java
    Replies: 2
    Last Post: 04-21-2011, 04:28 PM
  3. Generics Problem (Bound Mismatch)
    By castiel in forum New To Java
    Replies: 2
    Last Post: 02-16-2011, 12:05 AM
  4. Generics problem
    By ankur.trapasiya in forum New To Java
    Replies: 2
    Last Post: 01-22-2011, 05:09 PM
  5. Help with generics
    By shai in forum New To Java
    Replies: 0
    Last Post: 08-12-2010, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •