zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然JAVA开发JSP-Servlet学习笔记:JSP脚本

    <%@ page contentType="text/html; charset=GBK" language="java"
        errorPage=""%>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html>
    <head>
    <title>小脚本测试</title>
    </head>
    <body>
        <table bgcolor="#9999dd" border="1" width="300px">
            <!-- java脚本,这些脚本会对HTML的标签产生作用 -->
            <%
                for(int i=0; i<10; i++){
                    %>
            <tr>
                <td>循环值</td>
                <td><%=i %></td>
            </tr>
            <%
                }
             %>
        </table>
    </body>
    </html>

    <%@ page contentType="text/html; charset=GBK" language="java"
        errorPage=""%>
    
    <%@ page import="java.sql.Connection"%>
    <%@ page import="java.sql.DriverManager"%>
    <%@ page import="java.sql.SQLException"%>
    <%@ page import="java.sql.Statement"%>
    <%@ page import="java.sql.ResultSet"%>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>小脚本测试</title>
    </head>
    <body>
        <%!
        // 定义MySQL的数据库驱动程序
        public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
        // 定义MySQL数据库的连接地址
        public static final String DBURL = "jdbc:mysql://localhost:3306/taobao";
        // MySQL数据库的连接用户名
        public static final String DBUSER = "root";
        // MySQL数据库的连接密码
        public static final String DBPASS = "admin";
             %>
        <%        //注册数据库驱动
                Class.forName(DBDRIVER);
                //获取数据库连接
                Connection conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
                //创建Statement
                Statement stmt = conn.createStatement();
                //执行查询
                ResultSet rs = stmt.executeQuery("select * from person");
             %>
        <table bgcolor="#9999dd" border="1" width="300px">
            <%
                     //遍历结果集
                     while(rs.next()){
                         %>
            <tr>
                <td><%=rs.getInt(1) %></td>
                <td><%=rs.getString(2) %></td>
                <td><%=rs.getInt(3) %></td>
            </tr>
            <%
                     }
                  %>
        </table>
    </body>
    </html>

  • 相关阅读:
    poj3635(最短路)
    poj 3041( 最大匹配)
    poj 3522(生成树)
    poj 1904(强连通分量)
    poj 2446(二分匹配)
    poj 2400(最小权匹配)
    poj 2175(费用流消圈)
    poj 1256(搜索)
    poj 2195(最小费用流)
    poj 3613(最短路)
  • 原文地址:https://www.cnblogs.com/tszr/p/12663859.html
Copyright © 2011-2022 走看看