(1) 使用綠色版本JDK,解壓到一個目錄上D:\jdk1.6。
   (2) 使用綠色版本Tomcat,解壓到另一個目錄上D:\jdk1.6\tomcat5.5

    只要在bat文件D:\tomcat5.5\bin\catalina.bat,
    配置JAVA_HOME就可運行了。
    增加:set JAVA_HOME="D:\jdk1.6",這樣就可以運行了。

測試tomcat,訪問:  http://127.0.0.1:8080/,能打開訪問的頁面即可.

用一個簡單的投票系統。http://127.0.0.1:8080/vote/
投票系統(請不要下載,已經加密)

其中,有一個管理界面的mainform.jsp上有一個按鈕,修改數據,所鏈接的是isvisable.jsp, 點擊修改后,又返回mainform.jsp.
問題是: 不能刷新mainform.jsp,它還是顯示原來的數據.

故我用了一個簡單的解決方案:
         在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"); //去掉,不能直接返回,因更新數據庫,需要時間
   }
   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"); //去掉,不能直接返回,因更新數據庫,需要時間.
   }

  }
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<meta http-equiv="Refresh" content="1;url= mainform.jsp"> //等待1秒后,自動刷新到主頁面.
<title>
isvisable
</title>
</head>

</html>


有沒有好的方法呢?

原來只要正常的關閉連接就可以了,感覺是不是這樣就提交了,特別是要關閉connection,
問題解決了,看來還是要根據規范編寫程序才行,打開的鏈接,一定要關閉.

<%
 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>