Can I define a method in a JSP page?
Yes, you can. A JSP declaration is used to declare variables and methods in a page’s scripting language. The syntax for a declaration is as follows:
You must declare the variable or method before you use it in the JSP file. See JSP Declaration in JSP document.
For example,
<%!
public int getNumber() {
....
return num;
}
%>
My number is <%=getNumber()%>
Most Recent jsp Faqs
- How to get the real requested URI from inside the error page?
- Can I define a method in a JSP page?
- What is the difference between request.getParameter() and request.getAttribute()?
- What is difference between page and pageContext in JSP pages?
- How to config a JSP file in web.xml?
- What is the difference between jsp:forward and response.sendRedirect?
- How to retrieve values from HTML form input elements in JSP?
Most Viewed jsp Faqs
- What is difference between page and pageContext in JSP pages?
- How to config a JSP file in web.xml?
- How to disable browser caching for a specific JSP?
- How to retrieve values from HTML form input elements in JSP?
- What is the difference between jsp:forward and response.sendRedirect?
- How to get the current JSP page name?
- What is the difference between request.getParameter() and request.getAttribute()?