Declaration
Definition:
We can use this tag to declare class level declarations like static members, instance members, inner classes and static, instance method etc.
If you want to define methods or fields you can use JSP declaration. The JSP declaration is surrounded by the sign <%! and %>.
Syntax:
<%! Java code …. %> |
Description:
1. These declarations will be placed directly in the generated servlet, but outside of _jspService( ) method.
2. Every java statement inside declaration tag will should ends with semi colon.
3. A declaration doesn't contribute any HTML.
Example:test.jsp
<%@ page import="java.util.*" %> <HTML> <BODY> <%! Date d = new Date(); public Date getDate() { System.out.println( "In getDate() method" ); return d; } %> <h2>Hello! The time is now : : <%= getDate() %></h2> </BODY> </HTML> |
Output: http://localhost:8080/Scwcd_jsp/test.jsp
Note : All Jsp implicit object are local variables of _jspService ( ) so we can’t use jsp implicit objects directly in declaration tag.
No comments:
Post a Comment