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应用中重复提 ......
用了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? ......
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();
}
......
对于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);
%> ......
对于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);
%> ......
<%@ 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>
......
<%@ 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>
......