<%@ page import="java.util.Date" %><!doctype html> <html> <head> <meta charset="utf-8"> <title>JSP Test</title> </head>
<body> <% String str = "This is a string reference."; out.println(str);
int num = 10; out.println("<br>num=" + num);
int[] arr = {10, 15, 21, -1, 74, 64, 93, 225, 118, 176}; int n = arr.length; for (int i = 0; i < n; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] < arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } }
Date date = new Date(); %><form id="form1" name="form1" method="post"> <input name="sorted_numbers" type="text" value="<% for (int i = 0; i < n; i++) { out.print(arr[i]); if (i < n - 1) { out.print(" "); } } %>" size="50"><br> <input type="text" name="date" value="<%= date.toString() %>" size="30"> </form> <p><% StringBuffer sb = new StringBuffer("JSP"); out.println("<b>Capacity: </b>" + sb.capacity() + "<br>"); sb.append(" is easy to learn."); sb.insert(6, "n't"); out.println(sb); out.println("<br><b>Capacity Now: </b>" + sb.capacity() + "<br>"); sb.reverse(); out.println(sb); %></p> <p> <% long ln = 1278996457126849366L; num = (int)ln; short s = (short)ln; out.println(ln + ", " + num + ", " + s);
float f = 8.35f; out.println("<br>2f=" + f * 2); if (date instanceof Date) { out.println("<br><var>date</var> is an instance of Date."); } %></p> <p style="color:red"><% int cnt = 0; for (int i = 2; i < 1000; i++) { int j; int k = (int)Math.sqrt(i); for (j = 2; j <= k; j++) { if (i % j == 0) { break; } } if (j <= k) { continue; } cnt++; if (cnt == 10) { cnt = 0; out.print(i + "<br>"); } else { out.print(i + " "); } } %></p> </body> </html>
|