我是 html5&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>