0
我是html5的初學者& jsp, 我只想在roomlist從數據庫更改時進行檢索。 基本上當我點擊roomlist這是從我的主網頁的標題我可以得到roomlist但如果另一個用戶騰出空間,我不能實時獲得roomlist。請幫助我,謝謝如何從jsp中更改數據庫時檢索內容
聽到的是我的炫魅代碼
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*" %>
<% request.setCharacterEncoding("euc-kr"); %>
<html>
<Head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>RoomListing</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
<script type="text/javascript">
function ReloadPage() {
location.reload();
alert("hihi");
};
$(document).ready(function() {
alert("hi");
setInterval("ReLoadPage()", 3000);
});
</script>
</Head>
<body>
<section id="page1" data-role="page">
<%
//String subject = request.getParameter("subject");
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:8888/test",
"root", "1234");
if(conn==null)
throw new Exception("데이터베이스에 연결할 수 없습니다.<br>");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from roominfo");
ArrayList<String> room_list = new ArrayList<String>();
while(rs.next()){
room_list.add(rs.getString("id")+":"+rs.getString("subject")+":"+rs.getString("content"));
}
int num = room_list.size();
request.setAttribute("num", num);
for(int i=0; i<num; i++){
String room_name = null;
String max = room_list.get(i);
out.print("<input type ='button' id = 'button1' value = "+max+">");
request.setAttribute("room_name"+i, room_list.get(i));
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
stmt.close();
}catch (Exception ignored){
}
try {
conn.close();
}catch(Exception ignored){}
}
//RequestDispatcher dispatcher = request.getRequestDispatcher("RoomListing1.jsp");
//dispatcher.forward(request, response);
%>
</section>
</body>
</html>
謝謝,我只是解決問題...其實我把javascritp重載方法在此代碼的BUTTOM ...和它的工作。但如果我想只在數據庫發生變化時才上傳頁面,我應該使用ajax嗎?再次感謝 –