欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JSP生成九九乘法表的簡單實(shí)例

 更新時(shí)間:2017年09月27日 11:46:56   投稿:lqh  
這篇文章主要介紹了JSP生成九九乘法表的簡單實(shí)例,希望通過本文大家不僅實(shí)現(xiàn)九九乘法表還有掌握J(rèn)SP表達(dá)式的使用方法,需要的朋友可以參考下

JSP生成九九乘法表的簡單實(shí)例

一 用表達(dá)式和腳本方式實(shí)現(xiàn)九九乘法表

<%@ page language="java" import="java.util.*" contentType="text/html; charset=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%>" rel="external nofollow" >
  
  <title>My JSP 'exercise.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" rel="external nofollow" >
    -->
 
 </head>
 
 <body>
  <%!
    //返回九九乘法表對應(yīng)的HTML代碼,通過表達(dá)式來調(diào)用,在頁面上顯示
    String printMultiTable1()
    {
     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>"; //追加換行標(biāo)簽
     }
     return s;
    }
   
    //JSP內(nèi)置out對象,使用腳本方式調(diào)用,打印九九乘法表
    void printMultiTable2(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>"); //追加換行標(biāo)簽
     }
    }
   
  %>
  <h1>九九乘法表</h1>
  <hr>
  <%=printMultiTable1()%>
  <br>
  <% printMultiTable2(out);%>
  <br>
  
 </body>
</html>

 二 運(yùn)行效果

 

三 小知識點(diǎn)

1、pageEncoding是jsp文件本身的編碼。 

2、contentType的charset是服務(wù)器發(fā)給客戶端時(shí)的內(nèi)容編碼。

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論