用綠色版TOMCAT和綠色版JDK安裝一個WEB伺服器

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   sp   for   java   

 



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

用綠色版TOMCAT和綠色版JDK安裝一個WEB伺服器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.