?
???(1) 使用綠色版本JDK,解壓到一個(gè)目錄上D:\jdk1.6。
?? (2) 使用綠色版本Tomcat,解壓到另一個(gè)目錄上D:\jdk1.6\tomcat5.5
??? 只要在bat文件D:\tomcat5.5\bin\catalina.bat,
??? 配置JAVA_HOME就可運(yùn)行了。
??? 增加:set JAVA_HOME="D:\jdk1.6",這樣就可以運(yùn)行了。
測(cè)試tomcat,訪問(wèn):??
http://127.0.0.1:8080/
,能打開訪問(wèn)的頁(yè)面即可.
用一個(gè)簡(jiǎn)單的投票系統(tǒng)。
http://127.0.0.1:8080/vote/
投票系統(tǒng)
(請(qǐng)不要下載,已經(jīng)加密)
其中,有一個(gè)管理界面的mainform.jsp上有一個(gè)按鈕,修改數(shù)據(jù),所鏈接的是isvisable.jsp, 點(diǎn)擊修改后,又返回mainform.jsp.
問(wèn)題是: 不能刷新mainform.jsp,它還是顯示原來(lái)的數(shù)據(jù).
故我用了一個(gè)簡(jiǎn)單的解決方案:
???????? 在mainform.jsp上,禁止緩存,
如下:
<%response.setHeader("Cache-Control","no-store");%>
<%response.setHeader("Pragma","no-cache");%>
<%response.setDateHeader("Expires",0);%>
<head>
<META?? HTTP-EQUIV="pragma"?? CONTENT="no-cache">???
<META?? HTTP-EQUIV="Cache-Control"?? CONTENT="no-cache,?? must-revalidate">???
<META?? HTTP-EQUIV="expires"?? CONTENT="Mon,?? 23?? Jan?? 1978?? 20:52:30?? GMT">??
</head>
在isvisable.jsp中,
<%
?int questionid;
?int isvisable;
?questionid = Integer.parseInt(request.getParameter("questionid"));
?out.print(questionid);
?sql = "SELECT IsVisable from Questions where QuestionID ="+questionid;
?rs = smt.executeQuery(sql);
?out.println(rs);
?while(rs.next())
? {
?? isvisable = rs.getInt(1);
?? out.println(isvisable);
?? if(isvisable==1)
?? {
???? Statement smttmp?? =?? con.createStatement();?
???? sql = "update Questions set IsVisable = 0 ,IsOpen = 0 ,IsOpenDetial = 0 where QuestionID = "+questionid;
???? smttmp.executeUpdate(sql);
???? //response.sendRedirect("mainform.jsp"); //去掉,不能直接返回,因更新數(shù)據(jù)庫(kù),需要時(shí)間
?? }
?? else if(isvisable==0)
?? {
???? Statement smttmp?? =?? con.createStatement();?
???? sql = "update Questions set IsVisable = 1 ,IsOpen = 0 ,IsOpenDetial = 0 where QuestionID = "+questionid;
???? smttmp.executeUpdate(sql);
???? //response.sendRedirect("mainform.jsp"); //去掉,不能直接返回,因更新數(shù)據(jù)庫(kù),需要時(shí)間.
?? }
? }
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">?
<meta http-equiv="Refresh"?content="1;url= mainform.jsp"> //等待1秒后,自動(dòng)刷新到主頁(yè)面.
<title>
isvisable
</title>
</head>
</html>
有沒有好的方法呢?
原來(lái)只要正常的關(guān)閉連接就可以了,感覺是不是這樣就提交了,特別是要關(guān)閉connection,
問(wèn)題解決了,看來(lái)還是要根據(jù)規(guī)范編寫程序才行,打開的鏈接,一定要關(guān)閉.
<%
?int questionid;
?int isvisable;
?questionid = Integer.parseInt(request.getParameter("questionid"));
?out.print(questionid);
?sql = "SELECT IsVisable from Questions where QuestionID ="+questionid;
?rs = smt.executeQuery(sql);
?out.println(rs);
?while(rs.next())
? {
?? isvisable = rs.getInt(1);
?? out.println(isvisable);
?? if(isvisable==1)
?? {
???? Statement smttmp?? =?? con.createStatement();?
???? sql = "update Questions set IsVisable = 0 ,IsOpen = 0 ,IsOpenDetial = 0 where QuestionID = "+questionid;
???? smttmp.executeUpdate(sql);
???? if(smttmp != null)
???? {
???? smttmp.close();
???? }
???? response.sendRedirect("mainform.jsp");
?? }
?? else if(isvisable==0)
?? {
???? Statement smttmp?? =?? con.createStatement();?
???? sql = "update Questions set IsVisable = 1 ,IsOpen = 0 ,IsOpenDetial = 0 where QuestionID = "+questionid;
???? smttmp.executeUpdate(sql);
???? if(smttmp != null)
???? {
???? smttmp.close();
???? }
???? response.sendRedirect("mainform.jsp");;
?? }
? }
???? if(con != null)
???? {
???? con.close();
???? }
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">?
<title>
isvisable
</title>
</head>
</html>
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
