zoukankan      html  css  js  c++  java
  • jsp基本概念

    服务器启动的时候执行初始化init方法,只执行一次

    每次请求都会执行一次service方法

    服务器停止的时候执行destroy方法,也是只执行一次

    <%!
    //全局变量
    int initNum=0;
    int serviceNum=0;
    int destoryNum=0;


    %>

    <%!
    //书写两个方法
    public void jspInit(){
    initNum++;
    System.out.println("jspInit()============>执行了"+initNum);
    }

    public void jspDestory(){
    destoryNum++;
    System.out.println("jspDestory()============>执行了"+destoryNum);
    }

    %>


    <%

    serviceNum++;
    System.out.println("jspService()============>执行了"+serviceNum);

    %>

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
    contentType="text/html; charset=utf-8"
    %>
    <%--
    language:指定了jsp页面中使用的脚本语言
    import:引入使用的脚本语言所需要的类文件
    pageEncoding:当前页面的编码格式
    contentType:制定页面中的 MIME 类型,以及编码格式(在浏览器中显示的编码)
    --%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    %>
    <!DOCTYPE HTML>
    <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">
    </head>
    <body>
    <%--
    什么是内置对象?
       不需要声明和创建,就可以在jsp页面直接使用的成员变量!
    
    九大内置对象                    对应java中的类
    out              输出对象               JspWriter   
    request          请求对象                HttpServletRequest
    response         响应对象                 HttpServletResponse
    page             页面对象                this
    pageContext     页面的上下文对象    PageContext
    session          会话对象                 HttpSession
    application      应用程序对象         ServletContext
    config           配置对象                 ServletConfig
    exception        异常对象                 Throwable
    --%>
    
    
      
        <% 
        //局部变量  如果没有使用 在service中是不显示的
        //都在service方法中
           int a=5;
           int b=15;
        %>
      
        <%=a %>
        <%=b %>
      
      
       <%!
       //全局变量  
       private  int  num1=10;
       private  int  num2=10;
       
       public   int  add(){
           return num1+num2;
       }
       //单行注释
       /* 多行注释*/
       %>
      
      <!-- html注释  可以看到 -->
    <%-- jsp注释    用户在前台源码中看不到 --%>
     <% out.print(add()); %>
      <%=add() %>  <br/>
      
    <%-- 转义符 --%>
      <%=""哈哈"" %>
      
      
      
    </body>
    </html>
  • 相关阅读:
    关于同步解释
    dll 问题 (转)
    SQL SERVER 触发器中如何调用外部程序
    SQL SERVER所有表、字段名、主键、类型、长度、小数位数等信息
    variant 和 Stream 的互換
    Variant的相关函数
    使用 wxPython 创建“目录树”(5)
    wxPython 绘图演示——模拟雷达信号图(2)
    wxpython 实现简易画板(1)
    使用 wx.tools.img2py (4)
  • 原文地址:https://www.cnblogs.com/lyb0103/p/7293941.html
Copyright © 2011-2022 走看看