JSP supports various programming language codes. With the help of scripting elements, you can write java code inside the jsp page.
There are three types of scripting elements which are really useful for inserting java code.
- scriplet tag
With the help of this tag, java source could can be executed inside the jsp page.
syntax: <% [source code] %>
Example:
<html>
<body>
<% out.print("Hello"); %>
</body>
</html>
This is print hello in your browser.
2.Expression tag
This is used to display the values written inside the tag. No need to use out.println in this. eg. you can display values inside a variable. etc.
syntax: <%= [value]%>
Example:
<html>
<body>
<%= "Welcome" %>
</body>
</html>
This will print Welcome on your browser.
3.Declaration tag
Any method or variables which needs declaration are declared inside this tag.
syntax: <%!declarations %>
Example:
<html>
<body>
<%! int value=10; %>
<%= "The value declared is "+value %>
</body>
</html>
This will assign the variable 'value' with the value as '10' and it is then printed on your browser.
0 Comment(s)