易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 :

JSP避免Form重复提交的三种方案

  1 Javascript ,设置一个变量,只允许提交一次。
  #lt;script language="javascript"#gt;
   var checkSubmitFlg = false;
   function checkSubmit() {
   if (checkSubmitFlg == true) {
   return false;
   }
   checkSubmitFlg = true;
   return true;
   }
   document.ondblclick = function docondblclick() {
   window.event.returnValue = false;
   }
   document.onclick = function doconclick() {
   if (checkSubmitFlg) {
   window.event.returnValue = false;
   }
   }
  #lt;/script#gt;
  #lt;html:form action="myAction.do" method="post" onsubmit="return checkSubmit();"#gt;
  2 还是javascript,将提交按钮或者image置为disable
   #lt;html:form action="myAction.do" method="post"
   onsubmit="getElById('submitInput').disabled = true; return true;"#gt;
   #lt;html:image styleId="submitInput" src="images/ok_b.gif" border="0" /#gt;
   #lt;/html:form#gt;
  3 利用struts的同步令牌机制
  利用同步令牌(Token)机制来解决Web应用中重复提 ......

jsp上传文件到数据库和从数据库下载文件

用了commons-fileupload-1.2.jar和commons-io-1.3.2.jar这两个包。
save.jsp
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>保存上传文件</title>
</head>
<body bgcolor='#FFFFFF' text='#000000' leftmargin='0' topmargin='40' marginwidth='0' marginheight='0'>
<font size='6' color='blue'>文件列表:</font>
<center>
<table cellpadding=0 cellspacing=1 border=1 width='100%'>
<tr>
<td bgcolor=#008080>文件名</td>
<td bgcolor=#008080>大小</td>
</tr>
<%
// 连接字
String SQL_CON_DRIVER = "com.mysql.jdbc.Driver";
String SQL_CON_USERNAME = "root";
String SQL_CON_PASSWORD = "ddd";
String SQL_CON_STRING = "jdbc:mysql://localhost/ddd? ......

jsp中通过URL地址获取该地址页面中的静态页面


try {
            URL url = new URL("http://www.163.com");
            InputStream is = url.openStream();
            byte[] buffer = new byte[1024];
            int i;
            while((i = is.read(buffer)) != -1){
                System.out.println(new String(buffer,0,i));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } 
......

让html以及jsp页面不被缓存

对于HTM网页,加入:
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
然后,jsp页面中加入:
<%
     response.setHeader("Cache-Control","no-store");
     response.setHeader("Pragrma","no-cache");
     response.setDateHeader("Expires",0);
%> ......

让html以及jsp页面不被缓存

对于HTM网页,加入:
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
然后,jsp页面中加入:
<%
     response.setHeader("Cache-Control","no-store");
     response.setHeader("Pragrma","no-cache");
     response.setDateHeader("Expires",0);
%> ......

JSP文件

<%@ page language="java" import="kg.TestBean2;" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>HelloBean</title>
</head>
<body>
<%--
<%
kg.TestBean2 testbean=(kg.TestBean2)session.setAttribute("testbean");
if(testbean==null){
testbean = new kg.TestBean2();
session.setAttribute("testbean",testbean);
}
%>
--%>
<jsp:useBean id="testbean" class="kg.TestBean2" scope="page" />
<%--
<jsp:setProperty name="testbean" property="myText" />
<jsp:getProperty name="testbean" property="myText"/>
<jsp:setProperty name="testbean" property="myPassword"/>
<jsp:getProperty name="testbean" property="myPassword"/>
--%>
<jsp:setProperty name="testbean" property="*"/>
用户名:<%=new String(testbean.getMyText().getBytes("ISO8859_1"),"GBK")%>
密码:<%=testbean.getMyPassword()%>
</body>
</html>
......

JSP文件

<%@ page language="java" import="kg.TestBean2;" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>HelloBean</title>
</head>
<body>
<%--
<%
kg.TestBean2 testbean=(kg.TestBean2)session.setAttribute("testbean");
if(testbean==null){
testbean = new kg.TestBean2();
session.setAttribute("testbean",testbean);
}
%>
--%>
<jsp:useBean id="testbean" class="kg.TestBean2" scope="page" />
<%--
<jsp:setProperty name="testbean" property="myText" />
<jsp:getProperty name="testbean" property="myText"/>
<jsp:setProperty name="testbean" property="myPassword"/>
<jsp:getProperty name="testbean" property="myPassword"/>
--%>
<jsp:setProperty name="testbean" property="*"/>
用户名:<%=new String(testbean.getMyText().getBytes("ISO8859_1"),"GBK")%>
密码:<%=testbean.getMyPassword()%>
</body>
</html>
......
总记录数:40319; 总页数:6720; 每页6 条; 首页 上一页 [151] [152] [153] [154] 155 [156] [157] [158] [159] [160]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号