Saturday, March 14, 2009

How do you pass an InitParameter to a JSP? (JSP)

Question :How do you pass an InitParameter to a JSP? (JSP)
Answer :The JspPage interface defines the jspInit() and jspDestroy() method which
the page writer can use in their pages and are invoked in much the same
manner as the init() and destory() methods of a servlet. The example page
below enumerates through all the parameters and prints them to the
<%@ page import="java.util.*" %>
ServletConfig cfg =null;
public void jspInit(){
ServletConfig cfg=getServletConfig();
for (Enumeration e=cfg.getInitParameterNames(); e.hasMoreElements();)
String name=(String)e.nextElement();
String value = cfg.getInitParameter(name);

No comments: