Struts - 페이지 리로딩 및 다중전송 방지 (reload, refresch, submit)
목록  
제 목 페이지 리로딩 및 다중전송 방지 (reload, refresch, submit)
작성자 박세청 작성일 2008/08/20 10:07


Struts2  웹프레임워크를사용하는 경우는
Token Intercept를 사용하여 처리 합니다.

http://struts.apache.org/2.x/docs/token ··· tor.html
 
Back, Refresh, submit 두번클릭 방지 가능합니다.

1. Struts 설정파일에 Token Interceptor를 등록한다.

<action name="transfer" class="...OOOAction">
 <interceptor-ref name="defaultStack"/>
 <interceptor-ref name="token"/>
 <result name="invalid.token">doublePost.jsp</result>
 <result name="success">OOOO.jsp</result>
</action>

2. jsp 페이지에 token tag를 추가한다.

<s:form action="OOO">
 <s:token/>
 ...
 <s:submit value="OOOOO"/>
</s:form>
 
--원문

Ensures that only one request per token is processed. This interceptor can make sure that back buttons and double clicks don't cause un-intended side affects. For example, you can use this to prevent careless users who might double click on a "checkout" button at an online store. This interceptor uses a fairly primitive technique for when an invalid token is found: it returns the result invalid.token, which can be mapped in your action configuration. A more complex implementation, TokenSessionStoreInterceptor, can provide much better logic for when invalid tokens are found.

Note: To set a token in your form, you should use the token tag. This tag is required and must be used in the forms that submit to actions protected by this interceptor. Any request that does not provide a token (using the token tag) will be processed as a request with an invalid token.

Internationalization Note: The following key could be used to internationalized the action errors generated by this token interceptor

  • struts.messages.invalid.token

NOTE: As this method extends off MethodFilterInterceptor, it is capable of deciding if it is applicable only to selective methods in the action class. See MethodFilterInterceptor for more info.

Parameters

  • None

Extending the Interceptor

While not very common for users to extend, this interceptor is extended by the TokenSessionStoreInterceptor. The #handleInvalidToken and #handleValidToken methods are protected and available for more interesting logic, such as done with the token session interceptor.

Examples

<action name="someAction" class="com.examples.SomeAction">
    <interceptor-ref name="token"/>
    <interceptor-ref name="basicStack"/>
    <result name="success">good_result.ftl</result>
</action>

<-- In this case, myMethod of the action class will not
       get checked for invalidity of token -->
<action name="someAction" class="com.examples.SomeAction">
    <interceptor-ref name="token">
       <param name="excludeMethods">myMethod</param>
    </interceptor-ref name="token"/>
    <interceptor-ref name="basicStack"/>
    <result name="success">good_result.ftl</result>
</action>




이전글 한국스프링사용자모임에서 정리한 스트럿츠2(struts2) 자료
다음글 Velocity Eclipse UI plugin

목록