使用sessionID和時(shí)間戳作為標(biāo)識(shí),關(guān)鍵代碼如下:
public String execute(){
/**業(yè)務(wù)代碼**/
................
//設(shè)置標(biāo)識(shí)
this.setSessionToken();
//轉(zhuǎn)到添加頁(yè)面
return "toAdd";
}
public String reSave(){
if(this.token != null this.token.equals(this.getSessionToken())){
/**設(shè)置新標(biāo)識(shí)**/
this.setSessionToken();
/**業(yè)務(wù)代碼**/
..............
return "toAdd";
}else{
printWriter out = null;
try{
httpServletResponse.setContentType("text/html;charset=UTF-8");
out = httpServletResponse.getWriter();
out.println("script>alert('刷新提交表單!');/script>");
out.flush();
}catch(IOException e){
e.printStackTrace();
}finally{
if(out != null){
out.close();
}
}
}
return null;
}
}
public class BaseAction extends ActionSupport{
/**jsp頁(yè)面標(biāo)識(shí)**/
protected String token;
public String getToken(){
return token;
}
public void setToken(String token){
this.token = token;
}
public String getSessionToken(){
if(null != httpSession.getAttribute("Token")){
return httpSession.getAttribute("Token");
}else{
return null;
}
}
/**標(biāo)識(shí)生成**/
public void setSessionToken(){
String flag = useMd5(httpSession.getId() + System.currentTimeMillis());
httpSession.setAttribute("Token", flag);
httpServletRequest.setAttribute("SessionToken", flag);
}
/**MD5加密**/
private String useMd5(String str){
byte[] bs = str.getBytes();
String result = null;
try{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(bs);
result = md5.digest().toString();
}catch(NoSuchAlgorithmException e){
e.printStackTrace();
}finally{
}
return result;
}
}
JSP頁(yè)面設(shè)置標(biāo)識(shí)隱藏域:
標(biāo)簽:宿州 青島 江西 紅河 西藏 丹東 云浮 貴州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《JSP刷新頁(yè)面表單重復(fù)提交問題解決辦法分享》,本文關(guān)鍵詞 JSP,刷新,頁(yè)面,表單,重復(fù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。