• JSP第一次


    1.编写JSP页面,计算1-100之间的所有素数之和

     1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
     2 <%
     3     String path = request.getContextPath();
     4     String basePath = request.getScheme() + "://"
     5             + request.getServerName() + ":" + request.getServerPort()
     6             + path + "/";
     7 %>
     8 
     9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    10 <html>
    11 <head>
    12 <base href="<%=basePath%>">
    13 
    14 <title>My JSP 'index.jsp' starting page</title>
    15 <meta http-equiv="pragma" content="no-cache">
    16 <meta http-equiv="cache-control" content="no-cache">
    17 <meta http-equiv="expires" content="0">
    18 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    19 <meta http-equiv="description" content="This is my page">
    20 <!--
    21     <link rel="stylesheet" type="text/css" href="styles.css">
    22     -->
    23 </head>
    24 
    25 <body>
    26     <%
    27         int i, j, sum = 0;
    28         for (i = 1; i < 100; i++) {
    29             for (j = 2; j < i; j++) {
    30                 if (i % j == 0) {
    31                     break;
    32                 }
    33             }
    34             if (j == i) {
    35                 sum += i;
    36             }
    37         }
    38     %>
    39     1-100之间的素数之和为:
    40     <%=sum%>
    41 </body>
    42 </html>

    2.编写JSP页面,计算1-100之间的所有偶数之和

    <%@ 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>
        <%
            int i, sum = 0;
            for (i = 1; i <= 100; i++) {
                if (i % 2 == 0) {
                    sum += i;
                }
            }
        %>
        1-100之间的偶数之和为:
        <%=sum%>
    </body>
    </html>

  • 相关阅读:
    软件加载前显示加载中画面
    datatable用法
    arcsde安装
    dev gridcontrol (一)绑定值
    dev常用
    lookupedit用法(combox功能)
    关于NetBox2.8端口问题
    asp.net中,登录互斥的相关代码(不包含中途退出的处理)
    我老婆其人其事(一)
    判断文件是否为UTF8编码(以前收集的)
  • 原文地址:https://www.cnblogs.com/qq1123514689/p/14477393.html
Copyright © 2020-2023  润新知