zoukankan      html  css  js  c++  java
  • JSP学习(2)---四种基本语法与三种编译指令

    JSP的异常可以不处理,即使是checked异常。

    四种基本语法:

    jsp声明,jsp注释,jsp表达式,jsp脚本

    三种编译指令:

    page,include,taglib

    下面是具体的练习。

    show.jsp

    <%-- 编译指令--%>
    <%@page contentType="text/html;charset=UTF-8" language="java" errorPage="error.jsp"%>
    <%@page info="this is a jsp page"%>
    <html>
    <head>
    <title>
    欢迎
    </title>
    </head>
    <%-- 1.jsp声明变量和方法--%>
    <%!
    private int count;
    private int num;
    public String print(){
        return "hello";
    }
    %>
    <body>
    
    <%-- 2.jsp注释,不会出现在浏览器的源代码中。只在服务端。--%>
    <!--html注释-->
    你访问!
    <%out.print(new java.util.Date());%>
    <%for(int i=0;i<5;i++){
        out.print("<font size='"+i+"'>" );%>
        hello world</font>
        
        
    <%}%>
    
    <%-- 变量和方法使用--%>
    <%out.print(count++);
    %>
    <%out.print(print());%>
    <%-- 3.JSP表达式,尾部不能有分号--%>
    <%=num++%>
    <%=getServletInfo()%>
    
    <table border="1">
    <%-- 4.jsp脚本--%>
    <%for(int j=0;j<8;j++){%>
    <%!private int n;%>
    <tr><td>n++</td></tr>
        
    <%}%>
    
    <%-- 这里出现异常,跳转向error.jsp--%>
    <%!int m=7;
    int p=4;
    %>
    <%=m/p%>
    </table>
    </body>
    </html>

    error.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true"%>
    <html>
    <head><title>异常页面</title></head>
    <body>发生了内部异常</body>
    </html>

    include.jsp中包含show.jsp

    <%-- 编译指令需要和被包含页面一直,否则出错--%>
    <%@ page contentType="text/html;charset=UTF-8" language="java"%>
    <%@include file="show.jsp"%>
    <html>
    <head><title>包含页面</title></head>
    <body>包含了show.jsp页面</body>
    </html>

    include指令:

    包含于被包含页面出现指令冲突

     正常运行结果如下:

  • 相关阅读:
    Appium学习实践(二)Python简单脚本以及元素的属性设置
    Appium学习实践(三)测试用例脚本以及测试报告输出
    Appium学习实践(一)简易运行Appium
    Appium学习实践(四)结构优化
    js中对小数取整的函数
    C#基础 面试中常出现的问题
    repeater中的删除按钮实现
    js对fck编辑器取值 赋值
    jQuery对select操作
    进制转换(二进制 八进制 十进制 十六进制)
  • 原文地址:https://www.cnblogs.com/zhima-hu/p/8177117.html
Copyright © 2011-2022 走看看