In this JSP Tutorial, we will see how to declare a variable and Method. Then we will use the declared one in the body of the JSP Page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Variables amd Methods</title> </head> <%! //Sample 01: Declare Variable String var1 = "Sample String"; //Sample 02: Declare Functions private int addNumbers(int x, int y) { int result = 0; result = x + y; return result; } %> <body> <!-- //Sample03: Use it inside the JSP File --> <H2>Check Variables and Methods</H2> <p> Content of var1 is <%out.println(var1); %> </p> <p> The result of (10 + 4) is : <% out.println(addNumbers(10, 4)); %></p> </body> </html> |
Categories: JSP