Jsp16 07/10/2008
 

How do I have the JSP-generated servlet subclass my own custom servlet
class, instead of the default?


One should be very careful when having JSP pages extend custom servlet
classes as opposed to the default one generated by the JSP engine.
In doing so, you may lose out on any advanced optimization that may
be provided by the JSP engine. In any case, your new superclass has
to fulfill the contract with the JSP engine by:
Implementing the HttpJspPage interface, if the protocol used is HTTP,
or implementing JspPage otherwise Ensuring that all the methods in the
Servlet interface are declared final Additionally, your servlet
superclass also needs to do the following:

The service() method has to invoke the _jspService() method
The init() method has to invoke the jspInit() method
The destroy() method has to invoke jspDestroy()
If any of the above conditions are not satisfied, the JSP engine may
throw a translation error.
Once the superclass has been developed, you can have your JSP extend it
as follows:

<%@ page extends="packageName.ServletName" %>

How do you pass an InitParameter to a JSP?

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 console.

<%@ 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);
System.out.println(name+"="+value);
}
}
%>

Can we implement an interface in a JSP?

No

What is the difference between ServletContext and PageContext?

ServletContext: Gives the information about the container.
PageContext: Gives the information about the Request

How do I mix JSP and SSI #include?

If you're just including raw HTML, use the #include directive as usual inside your .jsp file.

But it's a little trickier if you want the server to evaluate any JSP
code that's inside the included file. If your data.inc file contains
jsp code you will have to use
<%@ include="data.inc" %>
The is used for including non-JSP files.

 


Comments




Leave a Reply

Name (required)
Email (not published)
Website


 
    Jsp Sets


    Archives

    July 2008

    RSS Feed