0

I need to open a connection pool in a tomcat servlet. In my jsp page I overwrite jspInit()

<%!
public void jspInit() {
. . .
}
%> 

Everything seems to be working fine, but i'm not sure if this is the correct way to initialize a connection pool. Does this jspInit() execute only once, i.e. when the very first user open this jsp page ?

My point is: when the second and the third etc. user opens the same .jsp page, this jspInit() get ignored as if it was not there at all ? So for the 2nd, 3rd, . . . users this jsp page does not have the jspInit() method executed

Emily
  • 511
  • 3
  • 11
  • 23

1 Answers1

0

Thats correct. Its called only once by the container during the lifecycle. Hence this method will be perfect for creating/opening a connection

Ref : http://www.coderanch.com/t/425072/java-Web-Component-SCWCD/certification/JSP

Rahman
  • 3,755
  • 3
  • 26
  • 43
  • Any resources confirming that? – Pshemo Oct 12 '15 at 18:15
  • Thank you, so `public void jspInit()` is the best place to open a conenction – Emily Oct 12 '15 at 18:18
  • @Pshemo Edited my answer to add the resource – Rahman Oct 12 '15 at 18:19
  • 1
    @Rehman I mean official resource. I may be wrong since my knowledge about JEE may be outdated but from what I remember one of reasons `init` was introduced to `Servlets` (and JSP are converted to servlets) was to let container reuse servlet objects. It simply calls `destroy()` when want to *unregister* them, and `init()` when register them again. – Pshemo Oct 12 '15 at 18:24
  • http://stackoverflow.com/questions/14464166/jsp-and-servlet-life-cycle-method - will it be enough ? – Rahman Oct 12 '15 at 18:33