File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes calling a method of a java class from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "calling a method of a java class from jsp" Watch "calling a method of a java class from jsp" New topic

calling a method of a java class from jsp

Nishad Banodkar

Joined: Jun 08, 2011
Posts: 5

i have a page called CollegeRegistration.jsp. in this page i am using one dropdown in which i need to get values from database.

i have called a method of that class using its object. This method returns an ArrayList.
i have done following coding
ArrayList universityName=CAPUtility.getUniversityNames();
getUniversityNames() method returns an arraylist which contains all values to be displayed in drop down.

when i run this page i get null pointer exception on for the above line....

please help me in same.a bit urgent...
Dieter Quickfend

Joined: Aug 06, 2010
Posts: 543

Not much information to go on, but calling that line from your JSP (I'm assuming you're using scriptlets to do this?) sounds like an A-team style explosion waiting to happen.

Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

The use of Java in JSPs has been discredited for almost 10 years now. Don't you think it's time to learn how to write JSP the correct way?

Fetch the database values in the controller and pass them to the JSP. It'll not only follow modern best practices, it will make it easier to debug such problems.

Please read this article for more information on properly structuring web applications.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: calling a method of a java class from jsp
It's not a secret anymore!