Question :How can I declare methods within my JSP page? (JSP)
Answer :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
file1.jsp:
<%@page contentType="text/html"%>
<%!
public void test(JspWriter writer) throws IOException{
writer.println("Hello!");
}
%>
file2.jsp
<%@include file="file1.jsp"%>
<%test(out);% >
www.interviewhelper.org is a hope for all the Job seekers. Users can find unlimited here. These range from technical to HR, from functional to behavioral. www.interviewhelper.org contains in the fields like Ajax,VB,Networking,Sharepoint,JEE,Perl,Javascript,Bioinformatics,Classic ASP,Unix,Linux,Accounting,Oracle DBA,Microprocessor,Bluetooth,jms,jme,.net framework,ABAP,ASP,ASP.net,Basic .net Framework,Interview Questions,C language,C++,database,Oracle,Java,PHP,LAMP,SAP etc.
Friday, March 13, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment