JSP - Beans - DBdata

I want to launch a JSP which needs to display a list of data (now using a default parameter but this will be dynamic)

From this list I choose an element which will then launch a second JSP. This second JSP will be used to view/ update/delete/write records.

This is how I try to implement this :

--

1)

I created a JSP (FreightQuotation.jsp) wich instantiates a Bean (FreightQuotationBean).

2)

By default this bean loads data from a database using a class (FreightQuotations) which is in the WebServer. This class has all methods on board to retrieve data in different way's. I tested this class on its own and it works fine (added a main() method).

3)

When the JSP is loaded, one beanfield is filled from within the bean itself and displayed on the HTML-page.

However, retrieving the data using the 'FreightQuotations' class doesn't work. No data is displayed in the HTML-page.

The WebServer-Logging shows following error :

java.lang.NullPointerException

com/clipper/objects/FreightQuotations.getPerAgent(Ljava/lang/String;)Ljava/util/Vector;+17 (FreightQuotations.java:221)

com/clipper/beans/FreightQuotationBean.getAS400data()V+8 (FreightQuotationBean.java:46)

com/clipper/beans/FreightQuotationBean.<init>()V+83 (FreightQuotationBean.java:28)

etc.etc...

btw, I'm rather new to Java and stepping into JSP's using MVC

[1453 byte] By [pgoovaerts] at [2007-9-26 2:10:27]
# 1
1.do your bean require any parameter , any set property ?2.check your database returns some value.3.you can go through the proffessional JSP Wrox pblications.if you have futher doubt you can contact me at rajarao_a@yahoo.co.uk
simmy1 at 2007-6-29 9:01:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi,

normally, beans require you to initialize the value of your variables in the bean constructor. When you instantiate objects via the new keyword, it should be done inside the bean constructor. if not, you'll get the NullPointerException. Based on the error you posted, I believe you have a Vector object. You should instantiate your Vector object inside your bean constructor. Your line that would say myVector = new Vector(); should be placed in your bean constructor and NOT in uppermost part of your code which declares the private variables that you will be using in your bean.

This should also go the same way with your FreightQuotation class if you are using the class via composition.

Example:

public class FreightQuotationBean {

Vector myVector;

FreightQuotation myFreightQuotation;

public FreightQuotationBean(){

myVector = new Vector();

myFreightQuotation = new FreightQuotation();

}

another thing, please make sure that the JDBC driver you are using is included in the classpath of your application server. this will make a difference when you are running the bean by itself by adding the main() method. When you run the JSP it does not see your DOS classpath or your IDE's classpath but rather see the classpath that you set in your application server. make sure that you JSP can see you JDBC driver. Have you been catching a ClassNotFoundError and try to put the error in a log so you would see if your JDBC driver is having a problem or not.

Hope this one helps. Should you need further help, you can email me at forever855@hotmail.com

Good luck!

Cris

pulat85 at 2007-6-29 9:01:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...