在JSP页面中声明局部变量,全局变量,方法等
代码示例:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>Insert title here</title> </head> <body> <% int i = 0; %> <%! int j = 0, k = 1; public int add() { return j + k; } %> i++:<%=i++%><br> j++:<%=j++%><br> k++:<%=k++%><br> add()<%=add()%> </body> </html>
注意:
<%! %>用来声明全局变量和方法,<% %>用来声明局部变量。