Declarations in JSP

By: Sathya Narayana Viewed: 153193 times    

The following syntax allows you to declare variables and methods for the page. These are placed in the generated servlet outside the _jspService() method; in other words, variables declared here will be instance variables of the servlet. Declarations don't produce any output.

This is an example of declaring a variable:

<%! String message; %>

The following code declares a variable and initializes it:

<%! String message = "variable declarared"; %>

You can define a method for use on the global page like so:

<%! public String showMessage() { return message; } %>

Declaration tags are mainly used in conjunction with scriptlets.

Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial