700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > JSP — 项目篇《I》【打印九九乘法表】

JSP — 项目篇《I》【打印九九乘法表】

时间:2020-12-08 19:40:42

相关推荐

JSP — 项目篇《I》【打印九九乘法表】

方法一:通过表达式

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%!String inputNiceNum(){String s = "";for(int i = 1;i<=9;i++){for(int j=1;j<=i;j++){s+=i+"*"+j+"="+(i*j)+"&nbsp;&nbsp;&nbsp;&nbsp;";}s+="<br>";//换行}return s;}%><h1>九九乘法表</h1><%=inputNiceNum()%></body></html>

方法二:通过脚本

<body><%!//注意:这里抛出了一个异常是因为,系统怀疑//out.println(i+"*"+j+"="+(i*j)+"&nbsp;&nbsp;&nbsp;&nbsp;");//可能会出现IO异常,所以不想捕获就要将其抛出////out 是一个内置对象,它的类型是 JspWriter void inputNiceNum(JspWriter out) throws Exception{for(int i=1;i<=9;i++){for(int j=1;j<=i;j++){out.println(i+"*"+j+"="+(i*j)+"&nbsp;&nbsp;&nbsp;&nbsp;");}out.println("<br>");//换行}}%><h1>九九乘法表</h1><hr><% inputNiceNum(out);%></body>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。