黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

JSP生成九九乘法表的簡單實例

jsp生成九九乘法表的簡單實例

一 用表達式和腳本方式實現(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>
  <%!
    //返回九九乘法表對應的html代碼,通過表達式來調(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>"; //追加換行標簽
     }
     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>"); //追加換行標簽
     }
    }
   
  %>
  <h1>九九乘法表</h1>
  <hr>
  <%=printmultitable1()%>
  <br>
  <% printmultitable2(out);%>
  <br>
  
 </body>
</html>

 二 運行效果

 

三 小知識點

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

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

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

相關(guān)文章