This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Servlet Query" Watch "Servlet Query" New topic
Author

Servlet Query

T sandya
Ranch Hand

Joined: Aug 03, 2006
Posts: 64
Hi Friends,

1.Can we overload and override the init(),service(),destroy() in servlet?

2.What about in JSP? jspinit()....

Regards,
Sandya.
Shashi Kant
Ranch Hand

Joined: Aug 08, 2006
Posts: 117
Hi Sandya

yes you can override the init(),service(),destroy() in servlet.

You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy().
The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations:
<%!
public void jspInit() {
. . .
}
%>
<%!
public void jspDestroy() {
. . .
}
%>


If it's true that we are here to help others, then what exactly are the others here for?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35446
    
    9
Note that generally you should not override the service method, but rather doGet or doPost. This is also mentioned in the javadocs.


Android appsImageJ pluginsJava web charts
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1318

Originally posted by T sandya:

1.Can we overload and override the init(),service(),destroy() in servlet?


The init method must complete successfully before the servlet can receive any requests. A servlet programmer can override this method to write initialization code that needs to run only once, such as loading a database driver, initializing values, and so on. In other cases, this method is normally left blank.

Follow this link to read more about the methods of javax.servlet.Servlet Interface


Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

You cannot override the _jspService() method within a JSP page


You can override _jspService() even though one would never need to.


Groovy
T sandya
Ranch Hand

Joined: Aug 03, 2006
Posts: 64
what about overloading?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

Originally posted by T sandya:
what about overloading?


You can always overload.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Servlet Query
 
Similar Threads
Export in Excel
Is there any way to get Servlet Init Parameter using EL?
How can I change the sdk version of Websphere 4 if I already install it
Capturing Form Data
javascript, servlets and SVG