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" /> 语句执行之前关闭数据库的连接,否则数据库连接将再也无法关闭,而如果数据库始终没有关闭,当达到一定程度时将会出现“数据库连接已经达到最大的异常”,此时就只能重启服务器。

 

 

转载于:https://www.cnblogs.com/softmans/p/3434371.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值