Originally posted by Sonalee Mohapatra:
normally all scriptlet code in a jsp goes into the _jspService() method of the generated servlet class for the jsp. Is there any way we can make java code go into the jspInit() method of the generated servlet instead ? we could override the jspInit() method in the jsp. is this the only way or is there some other way to do it ?
The jspInit method is similar to the init method in the javax.servlet.Servlet interface, and the jspDestroy method is analogous to the destroy method of the javax.servlet.Servlet interface. You can use the jspInit method to write initialization code.
I think this is the only way.
<%!
public void jspInit() {
// write your initialization code here
}
%>
<%
// other JSP page code and content
%>