How to declare methods within my JSP page?

You can declare methods for use within your JSP page as declarations. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions. Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare. For example:
<%! public String whereFrom(HttpServletRequest req) {
HttpSession ses = req.getSession();
return req.getRemoteHost(); } %>

<% out.print("Hi there, I see that you are coming in from "); %>
<%= whereFrom(request) %>

Another Example
<%@page contentType="text/html"%>
<%! public void test(JspWriter writer) throws IOException{
writer.println("Hello!"); } %>

<%@include file="file1.jsp"%>
<html> <body>
<%test(out);% >
</body>  </html>

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 JSP engine 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 the session 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.

Search Topics

Popular Posts