• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Passing ArrayList from Servlet to JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to pass ArrayList from Servlet to JSP but in JSP it showing Null Pointer Exception in line: for (int i=0;i<s.size();i++)
Please correct the error.




-------------------------------------------------------------

LandingController.java




-------------------------------------------------------

registration.jsp




-----------------------------------------------------------

web.xml







 
Saloon Keeper
Posts: 28325
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Haider!

We have a "Code" button on our message editor that can insert special Code Tags into the text you are editing. They can make pre-formatted text such as Java code and XML easier to read. I've added them to your post.

Your first error was in attempting to obtain the country list via a static reference from the country. Web applications are by nature, multi-user and static items are by nature single-user unless they are constant. But even in that case, it's generally preferable to store the shared item as an Application Scope object.

Your second "error" was in using brute-force scriptlet code on your JSP. A much tidier way of doing this is to use the Java Standard Template library (JSTL). The JSTL forEach tag can iterate over a sequential collection and retrieve each element in that collection as a loop variable. From there, you can simply use JEE Expression Language (EL) to read the element's properties. That is, instead of "x.getKey()", the EL equivalent is simply "x.key".

Scriptlets are virtually obsolete these days. Using stuff like JSTL/EL is simpler, more elegant, and less prone to bugs.
 
Greenhorn
Posts: 28
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include tag libraries and loop:



Just example.
 
I think she's lovely. It's this tiny ad that called her crazy:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic