struts2 action重复提交 在jsp、页面有一图片 图片链接的action是 <a href="jian?id=<%=rs.getInt(1)%>"><IMG src="images/jian.jpg" width="10"></a> 现在的问题是我每次刷新页面就会重复执行上一次的操作 求高手指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以使用jquery来做一个判断,如果触发了a连接,改变,不触发时,值不变 你可以使用jquery做一个判读,如果触发a,改变,没有触发a时值不变 用javascript的防止,或者用<s:token></s:token>再配置拦截器 <s:token></s:token>写在什么位置 改成 ,用js提交function doAction(){var action = jian?id=<%=rs.getInt(1)%>;document.forms[0].action = action;document.forms[0].submit;} <a href="javascript:0" onclick="doAction();"><IMG src="images/jian.jpg" width="10"></a> <s:token>写在struts.xml中,你要防止哪个action刷新重复提交,就写在那个action里,具体怎么写忘了,你google搜一下吧,有很多的 step 1:在<form>标签里面定义标签<s:token/>step 2:在struts.xml文件内配置token拦截器 <interceptor-ref name="token"> <param name="excludeMethods">....</param> //这里可以配置token拦截器的排除方法</interceptor-ref> 页面没有form 标签 只有一个图片链接的action,我要控制这个action的重复刷新 我用token实现过提交form表单的防刷新 但我现在页面没form表单 不知道token怎么用 <result type="redirectAction"/> 不能改成按钮加背景图吗id="<%=rs.getInt(1)%>"这个是放在表单元素里的吗?再根据表单id取一下值function doAction(){ var id=document.getElementById("").value(); window.location.href = '<%=path %>/jian?id='+id;}<input type="submit" name="submitButton" onclick="doAction()" style="background-image:images/jian.jpg "/> 试啦 不行啊 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%> <%String path = request.getContextPath();%> <%@ taglib uri="/struts-tags" prefix="s"%> <%@page import="java.sql.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>购物车</title><style type="text/css"><!--#Layer1 { width:750px; height:40px; z-index:1; top: 15px; border: 1px solid #EFEFEF; line-height: 40px;}.top{ font-size:12px; color:#000000;}.top:visited {color:#000000;}.top:link {color:#000000;}.top:hover {color:#000000;} .del{ font-size:12px; color:#FF0000;}.del:visited {color:#FF0000;}.del:link {color:#FF0000;}.del:hover {color:#FF0000;} .STYLE2 { color: #990000; font-weight: bold;}.STYLE3 {color: #0000FF}a:link { text-decoration: none;}a:visited { text-decoration: none;}a:hover { text-decoration: none;}a:active { text-decoration: none;}--></style></head><body><%String pic="";Connection sqlCon; Statement sqlStmt; ResultSet rs; String strCon; String strSQL; int intPageSize;int intRowCount; int intPageCount; int intPage; String strPage; int i; request.setCharacterEncoding("utf-8");String name =(String)request.getSession().getAttribute("id");intPageSize =100;strPage = request.getParameter("page"); if(strPage==null){ intPage = 1; } else{intPage = Integer.parseInt(strPage);if(intPage<1) intPage = 1; } try{ Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("加载驱动错误");} strCon = "jdbc:mysql://localhost:3306/Wfyg sqlCon = DriverManager.getConnection(strCon,"root","123"); sqlStmt = sqlCon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY strSQL="SELECT * FROM cart where c_user= "+name+" "; strSQL=new String(strSQL.getBytes("iso-8859-1"),"utf-8"); rs = sqlStmt.executeQuery(strSQL); rs.last(); intRowCount = rs.getRow(); intPageCount = (intRowCount+intPageSize-1) / intPageSize; if(intPage>intPageCount) intPage = intPageCount;%><table width="700" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><span class="STYLE2">我的购物车</span></td> </tr></table><table width="700" border="1" align="center" bordercolor="#EFEFEF" style="border-collapse: collapse" cellpadding="0" cellspacing="0"> <TR > <TH width=217 height="30" background="<%=path%>/images/cart_10.jpg"><font face="宋体">名称 </font> <TH width=70 height="10" background="<%=path%>/images/cart_10.jpg"><font face="宋体">图片</font> <TH width= 60 height="10" background="<%=path%>/images/cart_10.jpg"><font face="宋体">价格</font> <TH width=54 height="10" background="<%=path%>/images/cart_10.jpg"><font face="宋体">数量 </font> <TH width=228 height="10" background="<%=path%>/images/cart_10.jpg" ><font face="宋体">日期 </font> <TH width=57 height="10" background="<%=path%>/images/cart_10.jpg"> <font face="宋体">操作 </font> </TR><% if(intPageCount>0){ rs.absolute((intPage-1) * intPageSize + 1); //将记录指针定位到待显示页的第一条记录上 //显示数据i = 0; while(i<intPageSize && !rs.isAfterLast()){ if(rs.getString("pictur").trim().equals("admin.jpg")){ pic="../images/admin.jpg"; }else{ pic="upload/images/"+rs.getString("pictur"); }%> <TR> <TD ><div style="width: 217px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=rs.getString(3)%>"><%=rs.getString(3)%></div></TD> <TD ><div style="width: 70px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=pic%>"><img src=<%=path%>/<%=pic%> width="60" height="60"></div></TD> <TD ><div style="width: 60px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=rs.getString(5)%>"><%=rs.getString(5)%></div></TD> <td> <a href="jian?id=<%=rs.getInt(1)%>"><IMG src="images/jian.jpg" width="10" height="10" border="0" style="ADDING-LEFT: 0px; CURSOR: pointer" onclick='if (document.getElementById("number").value>1){document.getElementById("number").value--;};changePrice()'></a> <input name="goods.sl" type="text" id="number" value="<%=rs.getInt(7)%>" size="4" onBlur="changePrice()" style="border:1px solid #ccc; width:20px; height:19px; vertical-align:middle; padding-left:3px;" readonly/> <a href="jia?id=<%=rs.getInt(1)%>"><IMG src="images/jia.jpg" width="10" height="10" border="0" style="MARGIN: 0px;CURSOR: pointer" onclick='document.getElementById("number").value++;changePrice()'></a> </td> <TD ><div style="width: 228px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=rs.getString(4)%>"><%=rs.getString(4)%></div></TD> <TD ><div style="width: 50px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" ><a class="top" href="gmgoods?gmid=<%=rs.getInt("id")%>" target="_parent">购买</a></div> <div style="width: 50px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" ><a href="delcart?id=<%=rs.getInt(1)%>" class="del ">删除</a></div></TD></TR><% rs.next(); i++; } } %> </table> <% rs.close(); //关闭结果集 sqlStmt.close(); //关闭SQL语句对象sqlCon.close(); //关闭数据库 %><table width="700" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="350"><div align="left"><a href="index.jsp"><img src="<%=path%>/images/cart_goshopping.jpg" width="98" height="26" border="0"></a></div></td> <td width="350"><div align="right"><a href="plgoumai"><img src="<%=path%>/images/cart_gocart.jpg" width="98" height="26" border="0"></a></div></td> </tr></table></body></html> 就是刷新之前重定向到另一个action,比如,你往数据库中添加了一条记录之后重定向到记录列表,你再刷新它只会再次提交得到列表请求,而不会再次添加记录。 网址为 https://localhost/ 的网页可能暂时无法连接 JAVA SOCKET服务端运行一段时间端口不监听 如何解除spring对http请求的拦截 求教LDAP的分页怎么写? 《反模式》《敏捷开发》这两本本书怎么样? jsp往action传值问题,大家关注下 weblogic 9.2 MyEclipse部署应用程序问题 多线程如何debug 这段话,谁能给翻译或解释一下 我想調用同一個Service的兩個Method? 提交表单显示网页过期 spring+ibatis连接数据库如果用到getDatasouce,getconnection要关闭吗
再配置拦截器
var action = jian?id=<%=rs.getInt(1)%>;
document.forms[0].action = action;
document.forms[0].submit;
}
<a href="javascript:0" onclick="doAction();"><IMG
src="images/jian.jpg" width="10"></a>
<s:token>写在struts.xml中,你要防止哪个action刷新重复提交,就写在那个action里,具体怎么写忘了,你google搜一下吧,有很多的
id="<%=rs.getInt(1)%>"这个是放在表单元素里的吗?再根据表单id取一下值
function doAction(){
var id=document.getElementById("").value();
window.location.href = '<%=path %>/jian?id='+id;
}
<input type="submit" name="submitButton" onclick="doAction()" style="background-image:images/jian.jpg "/>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>购物车</title>
<style type="text/css">
<!--
#Layer1 {
width:750px;
height:40px;
z-index:1;
top: 15px;
border: 1px solid #EFEFEF;
line-height: 40px;
}
.top{ font-size:12px; color:#000000;}
.top:visited {color:#000000;}
.top:link {color:#000000;}
.top:hover {color:#000000;}
.del{ font-size:12px; color:#FF0000;}
.del:visited {color:#FF0000;}
.del:link {color:#FF0000;}
.del:hover {color:#FF0000;}
.STYLE2 {
color: #990000;
font-weight: bold;
}
.STYLE3 {color: #0000FF}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>
<body>
<%
String pic="";
Connection sqlCon;
Statement sqlStmt;
ResultSet rs;
String strCon;
String strSQL;
int intPageSize;
int intRowCount;
int intPageCount;
int intPage;
String strPage;
int i;
request.setCharacterEncoding("utf-8");
String name =(String)request.getSession().getAttribute("id");
intPageSize =100;
strPage = request.getParameter("page");
if(strPage==null){
intPage = 1;
}
else{
intPage = Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
try{
Class.forName("com.mysql.jdbc.Driver"); }
catch(ClassNotFoundException e){out.print("加载驱动错误");}
strCon = "jdbc:mysql://localhost:3306/Wfyg sqlCon = DriverManager.getConnection(strCon,"root","123"); sqlStmt = sqlCon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY strSQL="SELECT * FROM cart where c_user= "+name+" ";
strSQL=new String(strSQL.getBytes("iso-8859-1"),"utf-8");
rs = sqlStmt.executeQuery(strSQL);
rs.last();
intRowCount = rs.getRow();
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount) intPage = intPageCount;
%>
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><span class="STYLE2">我的购物车</span></td>
</tr>
</table>
<table width="700" border="1" align="center" bordercolor="#EFEFEF" style="border-collapse: collapse" cellpadding="0" cellspacing="0">
<TR >
<TH width=217 height="30" background="<%=path%>/images/cart_10.jpg"><font face="宋体">名称 </font>
<TH width=70 height="10" background="<%=path%>/images/cart_10.jpg"><font face="宋体">图片</font>
<TH width= 60 height="10" background="<%=path%>/images/cart_10.jpg"><font face="宋体">价格</font>
<TH width=54 height="10" background="<%=path%>/images/cart_10.jpg"><font face="宋体">数量 </font>
<TH width=228 height="10" background="<%=path%>/images/cart_10.jpg" ><font face="宋体">日期 </font>
<TH width=57 height="10" background="<%=path%>/images/cart_10.jpg"> <font face="宋体">操作 </font> </TR>
<%
if(intPageCount>0){
rs.absolute((intPage-1) * intPageSize + 1); //将记录指针定位到待显示页的第一条记录上
//显示数据
i = 0;
while(i<intPageSize && !rs.isAfterLast()){
if(rs.getString("pictur").trim().equals("admin.jpg")){
pic="../images/admin.jpg";
}else{
pic="upload/images/"+rs.getString("pictur");
}
%>
<TR>
<TD ><div style="width: 217px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=rs.getString(3)%>"><%=rs.getString(3)%></div></TD>
<TD ><div style="width: 70px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=pic%>"><img src=<%=path%>/<%=pic%> width="60" height="60"></div></TD>
<TD ><div style="width: 60px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=rs.getString(5)%>"><%=rs.getString(5)%></div></TD>
<td>
<a href="jian?id=<%=rs.getInt(1)%>"><IMG
src="images/jian.jpg" width="10" height="10" border="0" style="ADDING-LEFT: 0px; CURSOR: pointer"
onclick='if (document.getElementById("number").value>1){document.getElementById("number").value--;};changePrice()'></a>
<input name="goods.sl" type="text" id="number" value="<%=rs.getInt(7)%>" size="4" onBlur="changePrice()" style="border:1px solid #ccc; width:20px; height:19px; vertical-align:middle; padding-left:3px;" readonly/>
<a href="jia?id=<%=rs.getInt(1)%>"><IMG
src="images/jia.jpg" width="10" height="10" border="0" style="MARGIN: 0px;CURSOR: pointer"
onclick='document.getElementById("number").value++;changePrice()'></a> </td>
<TD ><div style="width: 228px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" title="<%=rs.getString(4)%>"><%=rs.getString(4)%></div></TD>
<TD ><div style="width: 50px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" ><a class="top" href="gmgoods?gmid=<%=rs.getInt("id")%>" target="_parent">购买</a></div>
<div style="width: 50px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" align="center" ><a href="delcart?id=<%=rs.getInt(1)%>" class="del ">删除</a></div></TD>
</TR>
<%
rs.next();
i++;
}
}
%>
</table>
<%
rs.close(); //关闭结果集
sqlStmt.close(); //关闭SQL语句对象
sqlCon.close(); //关闭数据库
%>
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="350"><div align="left"><a href="index.jsp"><img src="<%=path%>/images/cart_goshopping.jpg" width="98" height="26" border="0"></a></div></td>
<td width="350"><div align="right"><a href="plgoumai"><img src="<%=path%>/images/cart_gocart.jpg" width="98" height="26" border="0"></a></div></td>
</tr>
</table>
</body>
</html>