Thread: How to override the init and d

Forum : Java Server Pages (Jsp)   21-4-2017 06:09:19 AM
User Image
Sriman

Member

Joined: Jul 15, 2016

Points: 560

Threads: 641

Posts: 174

How to override the init and d

| Quote Date : Apr 21, 2017    Views:794    

How to override the init and destroy method in a JSP page?

tags: jsp j2ee

Comments

User Image
radhareddy

Newbie

Joined : Jun 27, 2017

Points : 165

Threads: 59

Posts: 123

Re: How to override the init and d

Reply Date : Jul 10, 2017

overriding the init and destroy method in a JSP page:

Yes one can override JSP init and destroy method but can?t override the _jspService method because whatever we write in our JSP page, goes to _jspService method that further compiled by servlet.So we can't override _jspService method. (_) symbol is the significance that the method won't be overridden.
 
Generally in the init method some initialization will be done and in the overridden destroy method, finalize operations are performed.Both the methods can be easily override inside a declaration in a JSP

<%!
 public void jspInit() {
  //logic
 }
%>

<%!  
public void jspDestroy() {
  //logic
 }
%>

 need in overriding jspInit() and jspDestroy() methods:

1) jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page.
2) jspDestroy() method is override to close the connections

User Image
Ravi3977

Newbie

Joined : Apr 20, 2017

Points : 100

Threads: 3

Posts: 17

Re: How to override the init and d

Reply Date : Jul 10, 2017

<%!
public void jspInit() { 
//here write the logic

%> 
<%! 
public void jspDestroy() { 
//here write the logic

%>?

Load More

No More Comments