• 暑假学习计划:Day_2. Response,Out,Config,Exception,pageContext对象。


    1.Response对象:

      a.自动刷新页面,每秒刷新一次:response.setHeader("refsh","1"); 

        ->网页显示时间,每一秒刷新一次。

        新建JSP,插入一下代码:

      

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <%@ page import="java.util.*" %>
     4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     5 <html>
     6 <head>
     7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     8 <title>Insert title here</title>
     9 </head>
    10 <body>
    11 <%
    12     //间隔一秒进行刷新
    13     response.setHeader("refresh","1");
    14     Date date = new Date();
    15 %>
    16 <font>This Time is:<%= date.toLocaleString() %></font>
    17 </body>
    18 </html>

      b.页面重定向,客户端跳转:response.setRedirect(urlStr),和页面刷新相似,不再单独写出代码。

      c.cookie操作:

        1).需知:i.Cookie类在java.util.cookie中

            ii.setMaxAge -> 设置cookie最大有效期。

            iii.post放在数据包中,get放在url中。get缺点:数据位短,安全性较低。

        2).开始操作了:

            i.设计登陆窗口:

           

            代码:

    <form action="Login.jsp" method="post">
        <table>
            <tr>
                <td>用户名:</td>
                <td><input type="text" id="userName" name="userName" value=<%= userName %>></td>
            </tr>
            
            <tr>
                <td>密   码:</td>
                <td><input type="password" id="pwd" name="pwd" value=<%= pwd %>></td>
            </tr>
            
            <tr>
                <td>记住密码</td>
                <td><input type="checkbox" id="remeber" name="remeber" value="rember-me"></td>
            </tr>
            
            <tr>
                <td><input type="submit" value="登陆"/></td>
                <td><input type="button" value="重置" onclick="resetValue()"/></td>
            </tr>
            
        </table>
    </form>

          3).插入JavaScript 代码,reetValue():

    1 <script type="text/javascript">
    2     function resetValue(){
    3         document.getElementById("userName").value="";
    4         document.getElementById("pwd").value="";
    5     }
    6 </script>

         4).设置userLogin代码:

          通过response.getParameter();获取userName和password。然后观察rember是否点击来确定是否回传cookie信息,然后客户端转发到登录页面。

     1 <%
     2     String userName = request.getParameter("userName");
     3     String pwd = request.getParameter("pwd");
     4     String remeber = request.getParameter("remeber");
     5     
     6     
     7     if("rember-me".equals(remeber)){
     8         Cookie userNameAndPwd = new Cookie("userNameAndPwd",userName + "-" + pwd);
     9         userNameAndPwd.setMaxAge(1*60*60*24*7);
    10         response.addCookie(userNameAndPwd);
    11         System.out.println("cookie设置成功");
    12     }
    13      response.sendRedirect("response03.jsp");
    14 %>

        5).设计response3的获取cookie代码:

     1 <%
     2     String userName = null;
     3     String pwd = null;
     4     Cookie []cookies = request.getCookies();
     5     for(int i=0;cookies != null && i<cookies.length  ;i++){
     6         if(cookies[i].getName().equals("userNameAndPwd")){
     7             userName = cookies[i].getValue().split("-")[0];
     8             pwd = cookies[i].getValue().split("-")[1];
     9             break;
    10         }
    11     }
    12     if(userName == null){
    13         userName = "";
    14     }
    15     if(pwd == null){
    16         pwd = "";
    17     }
    18 %>

     Out对象:

      

    2.Out对象:

       a.向客户端输出各种类型的数据。

       b.管理服务器的缓存。

       c.方法如下:

           public abstract void clear()
            清除缓冲区中的内容,不将数据发送至客户端。

           public abstract void clearBuffer()
           将数据发送至客户端后,清除缓冲区中的内容。

           public abstarct void close()
           关闭输出流。

           public abstract void flush()
           输出缓冲区中的数据。

           public int getBufferSize()
           获取缓冲区的大小。缓冲区的大小可用<%@ page buffer="size" %>设置。

           public abstract int getRemainning()
           获取缓冲区剩余空间的大小

           public boolean isAutoFlush()
           获取用<%@ page is AutoFlush="true/false"%>设置的AutoFlush值。

           public abstract void newLine()
           输出一个换行字符,换一行。

           public abstract void print()
           显示各种数据类型的内容。

           public abstract void println()
           分行显示各种数据类型的内容。 

    3.Config对象:JSP配置信息。

    4.Exception对象:异常对象。

      处理异常页面 <%@ errorPage = “ ” %>,通过页面跳转来处理异常。

    5.pageContext对象:可以获取所有的上下文的作用域的内容。

  • 相关阅读:
    Script:List NLS Parameters and Timezone
    Script:List Buffer Cache Details
    Know about RAC Clusterware Process OPROCD
    RAC Deadlock For Example
    Know more about redo log buffer and latches
    如何设计分区索引
    SCN may jump in a distributed transaction with dblink
    Script to Collect Log File Sync Diagnostic Information (lfsdiag.sql)
    Oracle学习笔记:10046 SQL tracle event
    Oracle学习笔记:创建physical standby
  • 原文地址:https://www.cnblogs.com/hixkill/p/7363685.html
Copyright © 2020-2023  润新知