Java Web之九九乘法表

 
  
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)+"&nbsp;&nbsp;&nbsp;"; 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)+"&nbsp;&nbsp;&nbsp;"); 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>

 

转载于:https://www.cnblogs.com/0Nullptr/p/6684784.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值