ajax+jsp局部页面刷新

更新时间:2023-05-29 05:23:45 阅读: 评论:0

ajax+jsp提取数据库记录并实现自动刷新页面
关键字: ajax+jsp提取数据库记录并实现自动刷新页面
  在web网站开发中,网页自动刷新的需求及功能已经屡见不鲜了,传统的用整体页面的刷新效果的实现对于网络速度受限的情况下显得就好些得不偿失了!
    这里将介绍一种使用Ajax技术实现网页的局部刷新的功能,只更新局部数据,而非页面全部,详细的源代码请如下所示吧:
其中,本人使用mysql数据库,news表的表结构为: 灯谜灯笼
size=large]描述          名称      是否为空    是否主键
新闻编号            newsId        Not Null        P
新闻内容            newsName    Not Null   
备注                BZ            Null          [size]   
首先:新建index.jsp如下:
<%@ page contentType="text/html; chart=gbk" language="java" %>
<html>
<HEAD><TITLE>用户登录页面</TITLE>
<script type="text/javascript">
大学三好学生
var xmlHttp;
var id;
function trim(str)     
{     
    var t = place(/(^/s*)|(/s*$)/g, "");  // 用正则表达式将前后空格       
    place(/(^ *)|( *$)/g, "");        // 用空字符串替代。     
}
function createXMLHttpRequest(){
  if(window.ActiveXObject){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  el if(window.XMLHttpRequest){
      xmlHttp=new XMLHttpRequest();
  }
}
function validate(){
  createXMLHttpRequest();
病毒的由来  var url="Del1.jsp";
  xmlHttp.open("GET",url,true);
  adystatechange=callback;
  xmlHttp.nd(null);
谜语猜一猜}
function callback(){
  adyState==4){
  show();
      tTimeout("validate()",3600);
  }
}
function show(){
  var sponXML;
  var ElementsByTagName("content");
  var ta="";
      for(var i=0;i<yan.length;i++){ 公关人员
      var y=yan[i];
      var name=y.childNodes[0].firstChild.data;
          ta+="<tr><td WIDTH=100% height=20><table width=100% height=100% cellpadding=0 cellspacing=0 border=0><tr><td>  "+name+"</td><td width=20% nowrap align=right></td></tr></table></td></tr>";
}
  ElementById("res").innerHTML=ta;
}
function startmarquee(lh,speed,delay) {
validate();
  var p=fal;
  var t;
  var ElementById("res");
  o.innerHTML+=o.innerHTML;
  o.style.marginTop=0;
  o.onmouover=function(){p=true;}
  o.onmouout=function(){p=fal;}
  function start(){
  t=tInterval(scrolling,speed);
  if(!p) o.style.marginTop=parInt(o.style.marginTop)-1+"px";
  }
  function scrolling(){
  if(parInt(o.style.marginTop)%lh!=0){
    o.style.marginTop=parInt(o.style.marginTop)-1+"px";
    if(Math.abs(parInt(o.style.marginTop))>=o.scrollHeight/2) o.style.marginTop=0;
  }el{
    clearInterval(t);
    tTimeout(start,delay);
  }
  }
  tTimeout(start,delay);
}
</script>
</head>
<BODY onLoad="startmarquee(90-18,40,0)">
<table height=44 cellSpacing=0 cellPadding=0 width=870 align=center bgColor=#ffffff border=0>
    <tr>
      <td vAlign=center align=middle>
        <table height=33 cellSpacing=1 cellPadding=0 width=860 align=center border=0>
          <tr>
            <td vAlign=center >
                         <font color="red" >${loginmessage } </font><form name="logform" action="/login.do" method="post">
                             用户名:<Input tabIndex=1 size=13 name="urname">
                  密码:<Input tabIndex=1 type=password size=13 value="" name="password">
                  <Input class="button2" type="submit" value=口令登录 name=B12 >
                      <Input class="button2" type="ret" value=重置 name=ret2 >
                                 
  </form>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
<div id="res"></div>
</BODY>
</html> 声音笑貌
然后,新建Conn.jsp,用于每个页面调用:
<%@ page contentType="text/html; chart=utf-8" import="java.sql.*, javax.naming.Context, javax.naming.InitialContext"
errorPage=""%>
动量轮<%!Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public void jspInit() {
try {
//Class.forName("sql.jdbc.Driver");
//建立连接
//conn = Connection( 盆栽金桔怎么养
// "jdbc:mysql://localhost:3306/SKY5", "root", "123456");
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env");
//获取连接池对象

本文发布于:2023-05-29 05:23:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/804446.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:实现   页面   刷新   自动
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图