• 吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:JSP4种基本语法


    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    This program is protected by copyright laws.
    Program Name:
    Date: 
    --%>
    
    <%@ 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 xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> 注释示例 </title>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <body>
    注释示例
    <!-- 增加JSP注释 -->
    <%-- JSP注释部分 --%>
    <!-- 增加HTML注释 -->
    <!-- HTML注释部分 -->
    </body>
    </html>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    This program is protected by copyright laws.
    Program Name:
    Date: 
    --%>
    
    <%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
    <%@ page import="java.sql.*" %>
    <!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>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <body>
    <%
    // 注册数据库驱动
    Class.forName("com.mysql.jdbc.Driver");
    // 获取数据库连接
    Connection conn = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/javaee","root","32147");
    // 创建Statement
    Statement stmt = conn.createStatement();
    // 执行查询
    ResultSet rs = stmt.executeQuery("select * from news_inf");
    %>
    <table bgcolor="#9999dd" border="1" width="300">
    <%
    // 遍历结果集
    while(rs.next())
    {%>
        <tr>
            <!-- 输出结果集 -->
            <td><%=rs.getString(1)%></td>
            <td><%=rs.getString(2)%></td>
        </tr>
    <%}%>
    <table>
    </body>
    </html>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    This program is protected by copyright laws.
    Program Name:
    Date: 
    --%>
    
    <%@ 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 xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> 声明示例 </title>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <!-- 下面是JSP声明部分 -->
    <%!
    //声明一个整形变量
    public int count;
    //声明一个方法
    public String info()
    {
        return "hello";
    }
    %>
    <body>
    <%
    //将count的值输出后再加1
    out.println(count++);
    %>
    <br/>
    <%
    //输出info()方法的返回值
    out.println(info());
    %>
    </body>
    </html>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    This program is protected by copyright laws.
    Program Name:
    Date: 
    --%>
    
    <%@ 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 xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> 输出表达式值 </title>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <%!
    public int count;
    
    public String info()
    {
        return "hello";
    }
    %>
    <body>
    <!-- 使用表达式输出变量值 -->
    <%=count++%>
    <br/>
    <!-- 使用表达式输出方法返回值 -->
    <%=info()%>
    </body>
    </html>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    This program is protected by copyright laws.
    Program Name:
    Date: 
    --%>
    
    <%@ 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 xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title> 小脚本测试 </title>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <body>
    <table bgcolor="#9999dd" border="1" width="300px">
    <!-- Java脚本,这些脚本会对HTML的标签产生作用 -->
    <%
    for(int i = 0 ; i < 10 ; i++)
    {
    %>
        <!-- 上面的循环将控制<tr>标签循环 -->
        <tr>
            <td>循环值:</td>
            <td><%=i%></td>
        </tr>
    <%
    }
    %>
    <table>
    </body>
    </html>
    <?xml version="1.0" encoding="GBK"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
        version="3.1">
    </web-app>
  • 相关阅读:
    lambda表达式
    Java的MongoDB驱动及读写策略
    MongDB主从复制、复制集
    PL/SQL练习
    MySQL数据库MyISAM和InnoDB存储引擎的比较(转)
    Java的垃圾回收概述
    springMVC源码浅析
    ActiveMQ使用总结
    常用的缓存产品比较
    Nginx+tomcat负载均衡并动静态分离
  • 原文地址:https://www.cnblogs.com/tszr/p/12363825.html
Copyright © 2020-2023  润新知