• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jspInit() method

 
Sonalee Mohapatra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you will take a look at the javax.servlet.jsp package, JspPage interface JAVADOCS, you will find your answer.
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
%>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic