<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html><head><title>利用Ajax重构</title><scriptlanguage="JavaScript"src="../JS/AjaxRequest.js"></script><scriptlanguage="JavaScript">functiononerror(){alert("what you have operated is wrong");}functiongetInfo(){var loader =newnet.AjaxRequest("getInfo.jsp?nocache="+newDate().getTime(),deal_getInfo,onerror,"GET");}functiondeal_getInfo(){
document.getElementById("showInfo").innerHTML =this.req.responseText;}
window.onload=function(){getInfo();//调用getInfo()方法获取公告信息}</script><styletype="text/css">body{background: #bdd4e9;align-items: center;}</style></head><body><center><divstyle="border: 1px solid;height: 100px;width:200px;padding: 5px;"><divid="showInfo"></div></div></center></body></html>
在编写一个 getInfo.jsp 用于处理
<%@ page contentType="text/html;charset=UTF-8" language="java"%><%@ page import="java.sql.ResultSet"%><%@ page import="java.sql.SQLException"%><jsp:useBean id="conn"class="com.lyq.DB.ConnDB" scope="page"></jsp:useBean><ul><%
ResultSet rs = conn.Query("select name from tb_books order by id DESC");try{if(rs.next()){do{
out.print("<li>"+rs.getString(1)+"</li>");}while(rs.next());}else{
out.print("<li>暂无书籍信息!</li>");}}catch(SQLException e){
e.printStackTrace();}%></ul>