Can I write method in JSP file?

Can I write method in JSP file?

Postby Kishan » Mon Feb 18, 2013 6:55 am

Can I write method in JSP file? Any Example?
Kishan
 
Posts: 191
Joined: Tue Jan 29, 2013 4:21 am

Re: Can I write method in JSP file?

Postby Kishan » Mon Feb 25, 2013 4:37 am

Yes, you can write JSP method's in JSP declaration element and you can invoke them from JSP scriptlet and expression.

Example:

Code: Select all
<%!
public int sum(int i, int j) {
    return i + j;
}
%>

Sum Output: <%=sum(2,3)%>


Output above code:
Sum Output: 5
Kishan
 
Posts: 191
Joined: Tue Jan 29, 2013 4:21 am


Return to JSP

Who is online

Users browsing this forum: No registered users and 1 guest

cron