zoukankan      html  css  js  c++  java
  • JAVA中Response的几种用法(设定时间调整到指定页面 ....... )

    <%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>Response的使用案例</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">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
      </head>
      
      <body>
          <%
            response.setHeader("refresh", "10;URL=S.jsp");//定义10秒刷新 跳入到 S.jsp页面
                                         // 当时间设置为 0 ,是则为操作后直接跳转至那个页面。 
    %> </body> </html>

     另外是 :设定规格时间内进行 某某 操作:

    <%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>Response的使用案例</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">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
      </head>
      
      <body>
        <%!
        int count=0;
         %>
          <%
            response.setHeader("refresh", "2");//定义两秒刷新一次
         %>
          <h2>已经访问   <%=count++%> 次了 ... ... </h2>
      </body>
    </html>

     注意: 页面间的调整,html也可以实现:

    <!DOCTYPE html>
    <html>
      <head>
        <title>jup.html</title>
        
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta http-equiv="refresh" content="4;URL=IsOldUse.jsp">
        
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
    
      </head>
      
      <body>
        4秒后跳转到 其他页面!!! <br>
      </body>
    </html>

     页面之间的跳转  (response.sendRedirect() 客户端跳转)  || (<jsp:forward page="hello.html" /> 服务器端跳转)

     区别:

    客户端的跳转:它是执行完整个页面,并且URL地址栏发生改变,在某些传值的情况下不可使用,

    服务器端跳转:他是执行到  <jsp:forward page="hello.html" /> 就马上停止,不再继续执行,而他的地址栏URL不变。

      注意:在以后的开发过程中,尤其是在使用JDBC的操作中,一定要在  <jsp:forward page="hello.html" /> 语句执行之前关闭数据库的连接,否则数据库连接将再也无法关闭,而如果数据库始终没有关闭,当达到一定程度时将会出现“数据库连接已经达到最大的异常”,此时就只能重启服务器。

  • 相关阅读:
    Delphi的几个跨平台小游戏例子。
    Delphi判断某个类是否实现了某个接口
    Delphi RAD Server 应用服务基础平台
    Delphi XE10.1 引用计数
    运行Delphi XE10的MongoDB例程,测试Delphi插入记录性能
    在Windows下编译mongo-c-driver 1.3.x
    Delphi 高效读写锁
    Delphi XE10在 Android下调用静态库a文件
    Delphi 调试连接 任意Android手机/平板/盒子
    Some cool FireMonkey multi-device components
  • 原文地址:https://www.cnblogs.com/softmans/p/3434371.html
Copyright © 2011-2022 走看看