JSP on the server side to determine whether the form is repeatedly submitted instances

Source: Internet
Author: User

On the server side to determine whether the form is repeated, the main consideration in the page through the session to share the flag variable method to achieve, that is, in the client page set session in the flag variable, and then in the server segment on the session of the flag variable to judge.

1. Create a new servertest.jsp file with the following code:

<%@ page language="java" contentType="text/html; charset=Gb2312"
  pageEncoding="Gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>提交页面</title>
  <%
    //设置标志变量SubmitFlag值ServerTest.jsp
    session.putValue("SubmitFlag","ServerTest.jsp");
  %>
<body bgcolor="#ffffff">
  <form name="form_client" action="ServerSubmit.jsp">
    <input type="checkbox" name="check_1" checked=true/>人在江湖
    <input type="submit" name="submitok"/>
  </form>
</body>

2. Create a new serversubmit.jsp with the following code:

<%@ page language="java" contentType="text/html; charset=Gb2312"
  pageEncoding="Gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=Gb2312">
<title>服务器端程序</title>
  <%
    String PageFlag;
    PageFlag=(String) session.getValue("SubmitFlag");
    if(PageFlag=="Over"){
      out.println("重复提交页面!");
    }else{
      //设置标志变量SubmitFlag值为Over,表示已经提交
      session.putValue("SubmitFlag","Over");
      out.println("正常业务逻辑处理...请等待!!!");
    }
  %>
<body>
</body>

3. When you click Submit Query, click Back, and then click the Submit Query Content button again to prompt for a duplicate commit error.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.