1
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> <%! public String str="hello"; public String info(){ return "hello world"; } %> <%out.println(this.str)%> </body> </html>
2
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> <%! int i=10; %> <% if(i>10){ %> <span>i>10</span> <%%> <%}else {%> <span>i<10</span> <%}%> </body> </html>
3
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> <%! int i=5;%> <% int j=10; j++; i++; %> <% out.println("i:"+i); out.println("<br>"); out.println("j:"+j); %> </body> </html>
4
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> <%! int i=10;%> i的值是:<%=i%> <% out.println("</br>"); out.println("i:"+i); %> </body> </html>
5
<%@ page import="java.util.*"%> <%@ page import="java.text.*"%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> <%! public String getNow(){ SimpleDateFormat simple = new SimpleDateFormat(); //DateFormat的子类:SimpleDateFormat日期/时间格式化子类, // 允许进行格式化(也就是日期 -> 文本)、解析(文本-> 日期)和标准化。 Date currentTime= new Date(); return simple.format(currentTime); } %> <%=getNow()%> </body> </html>