NineTabs.jsp
1 <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
2 <%
3 String path = request.getContextPath();
4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5 %>
6
7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
8 <html>
9 <head>
10 <base href="<%=basePath%>">
11
12 <title>My JSP 'NineTabs.jsp' starting page</title>
13
14 <meta http-equiv="pragma" content="no-cache">
15 <meta http-equiv="cache-control" content="no-cache">
16 <meta http-equiv="expires" content="0">
17 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
18 <meta http-equiv="description" content="This is my page">
19 <!--
20 <link rel="stylesheet" type="text/css" href="styles.css">
21 -->
22
23 </head>
24
25 <body>
26 <%!
27 //返回九九乘法表对应的html代码,通过表达式来调用,在页面上显示
28 String printMultiTable1(){
29 String s=" ";
30 for(int i=1;i<10;i++){
31 for(int j=1;j<=i;j++){
32 s+=i+"*"+j+"="+(i*j)+" ";
33 }
34 s+="<br>";//追加换行标签
35 }
36 return s;
37 }
38
39 //JSP内置out对象,使用脚本方式调用,打印九九乘法表
40 void printMultiTable2(JspWriter out) throws Exception{
41 for(int i=1;i<10;i++){
42 for(int j=1;j<=i;j++){
43 out.println(i+"*"+j+"="+(i*j)+" ");
44 }
45 out.println("<br>");//追加换行标签
46 }
47 }
48 %>
49
50 <h1>九九乘法表</h1>
51 <hr>
52 <%=printMultiTable1()%>
53 <br>
54 <% printMultiTable2(out); %>
55 <br>
56 </body>
57 </html>