I am creating a web app using java. I am very new to this, and I have the following questions:
-
I have
jspfiles for the front-end. Now, whenever I have to do a bulky back-end function I can either create a servlet and do a get request from jsp or I can create a simple java object, instantiate it in jsp and use it for backed function.
Which one is better and why? -
Each back-end function needs to connect to a database. I want to do it only once for a user for the entire session and for all
jsppages. How is it done?
For question 1:
If no servlet is needed why use it? Just do your bulky work in a plain Java class. By this way you will have less dependencies in you workflow.
For question 2:
Most app servers now have build in support for pooled connections. It is strongly adviced that you make use of this functionality. Now, there are plenty of ways you can go forward. The simplest and IMO best way is to create a database related Object that will handle connection open/close, perform updates/delete/select functions, and make use of this through out your application