Java Form Class Double-click Submit

Source: Internet
Author: User

Double-click System sometimes some operations can be very time consuming (long lived operation), such as the export of this database, table table generation, etc. Sometimes the user of the program sees a long time server

No response, preferring to click the Submit button multiple times. On the contrary, the response time is slower because the server is re-run for the same long time.

How do we make this kind of operation? Can we automatically generate a special hidden field when each page is generated, and this hidden field is unique. Each time a request is submitted to the server

, the server will record this hidden field, when the content of the same special field to see the submission, the server think this is a duplicate submission, the screen is positioned to a special screen to remind the customer to repeat the

Data.

In Struts2, the content of the double-click on the system operation, the special hidden field is called token.

How do I generate a token field when I generate a page? Use the token tag. The code is as follows:

<s:url id= "Formurl" action= "Longlivedtokenaction"/>

<s:form action= "%{formurl}" method= "POST" >

<s:token/>

<s:textfield name= "name" label= "name"/>

<s:textfield name= "password" label= "password"/>

<s:submit/>

</s:form>

Where the <s:token/> tag is used to generate a unique hidden field, the content generated at run time is as follows: <input type= "hidden"

Name= "Struts.token" value= "C21zwheh0q4b6fy15zo5bfm1i9w8siqh"/>

How do I record tokens that have been submitted on the server? You can use token intercepter. The code is as follows:

<action name= "longlivedtokenaction" class= "Com.jpleasure.LongLivedTokenAction" >

<interceptor-ref name= "token"/>

<interceptor-ref name= "Basicstack"/>

<result>/jsp/longLived.jsp</result>

<result name= "Invalid.token" >/jsp/invalidToken.jsp</result>

</action>

The above <interceptor-ref name= "token"/> that all requests must go through token Interceptor,token Interceptor function to record all tokens that have been submitted. So hair

What happens when the token being submitted is repeatedly submitted? As you may have guessed, he redirects to the page Invalid.token points to, which is/jsp/invalidtoken.jsp.

Based on the order in which the interceptor is defined in Struts.xml, the token interceptor should be placed at the top of all interceptor in order to end the processing of the duplicate commits earlier.

With the token interceptor above, the client can be prevented from repeating the submission, greatly reducing the load on the server. But for users, it may be inconvenient, accidentally clicked the Submit button, into

into the Invalid.token page, will never go back, the above operation will no longer see.

Wait for the screen can we provide a waiting screen? Each time we submit a picture immediately after the screen is migrated to a similar status bar, this screen is constantly requesting the server to determine whether the action

Once the action is finished, immediately navigate to the correct screen. It's not better.

STRUTS2 also provides support for the wait screen. First, when we submit the completion of the screen before the scene of a page called waiting for the screen. Wait for the screen to submit a request to the server periodically to determine the service

Whether the service operation is complete. Another action that is being executed requires a blocking object that intercepts every request on the waiting page, telling the waiting page whether the processing is complete.

First we need to define, wait for the page and the action to complete the interception object

<action name= "longlivedaction" class= "com.jpleasure.LongLivedAction" > <interceptor-ref name= " Completestack "/>

<interceptor-ref name= "execandwait"/>

<result name= "Wait" >/jsp/wait.jsp</result>

<result name= "Success" >/jsp/after.jsp</result>

</action>

<result name= "Wait" >/jsp/wait.jsp</result> defines the wait screen is/jsp/wait.jsp, when we submit a request to the server, the screen will be migrated to this screen.

<interceptor-ref name= "execandwait"/> defines a blocking object that tells the wait screen whether it has completed a lengthy operation. So wait for the screen how to regularly query it? The need for a

A constant refresh that points to the action call. The code is as follows:

<%@ page contenttype= "Text/html;charset=utf-8" language= "java"%> <% @taglib prefix= "s" uri= "/struts-tags"% >

<title>please wait</title>

<meta http-equiv= "Refresh" content= "5;url=<s:url includeparams= ' all '/>"/>

<body>

</body>

Please wait while we process your request. <a href= "<s:url includeparams=" All "/>" > Click here</a> If this page does not reload

automatically.

The above-mentioned bold part indicates that once the screen is established, a refresh is established, refreshed every 5 seconds, and flushed with Url=<s:url includeparams= "All"/>,meta is standard browser support

One of the contents.

You can see what is generated when you run it:

<meta http-equiv= "Refresh" content= "5;url=/wait/jsp/longlivedaction.action?name=zhangsf&value=119"/>

It does not matter if the browser does not support automatic refresh, so the customer can click here to determine if the operation is complete.

In fact, the most important here is execandwait interceptor, each time it intercepts the action to send a request, execandwait will determine whether the action is completed, if completed, the screen

Navigate to the corresponding page (usually the page that success points to), or the page where the carton wait points.

Java Form Class Double-click Submit

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.