Programming Tutorials

Declarations in JSP

By: Sathya Narayana in JSP Tutorials on 2010-10-24  

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.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in JSP )

Latest Articles (in JSP)