Jsp9 07/10/2008

How can I set a cookie and delete a cookie from within a JSP page?

A cookie, mycookie, can be deleted using the following scriptlet:<%//creating a cookieCookie mycookie = new Cookie("aName","aValue");response.addCookie(mycookie);//delete a cookieCookie killMyCookie = new Cookie("mycookie", null);killMyCookie.setMaxAge(0);killMyCookie.setPath("/");response.addCookie(killMyCookie);%>

Is there a way I can set the inactivity lease period on a per-session basis?

Typically, a default inactivity lease period for all sessions is set within your JSPengine admin screen or associated properties file. However, if your JSP engine supports the Servlet 2.1 API, you can manage the inactivity lease period on a per-session basis. This is done by invoking the HttpSession.setMaxInactiveInterval() method, right after thesession has been created.For example:<%session.setMaxInactiveInterval(300);%>would reset the inactivity period for this session to 5 minutes. The inactivity interval is set in seconds.

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 JSPengine.In any case, your new superclass has to fulfill the contract with the JSP engine by: Implementingthe 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() methodThe init() method has to invoke the jspInit() methodThe 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 control from one JSP page to another?

Use the following ways to pass control of a request from one servlet to another or one jsp to another.· The RequestDispatcher object ‘s forward method to pass the control.· The response.sendRedirect method

How do you restrict page errors display in the JSP page?

You first set "Errorpage" attribute of PAGE directory to the name of the error page (ie Errorpage="error.jsp")in your jsp page .Then in the error jsp page set "isErrorpage=TRUE". When an error occur in your jsp page it will automatically call the error page



Leave a Reply

Name (required)
Email (not published)

    Jsp Sets


    July 2008

    RSS Feed