struts 2 token 실현 방식

1669 단어 자바web
1
    struts 2 의 token 탭 은 페이지 에서 생 성 됩 니 다.
 
< input type ="hidden" name ="struts.token.name" value ="struts.token" />
< input type ="hidden" name ="struts.token" value ="KUGRKLACCF1SZEKY1Z8O3KR2RLCRP3KK" />
이 두 숨겨 진 도 메 인 은 이 페이지 가 유일 하 다 는 것 을 확인 합 니 다.새로 고침 하거나 다음 에 이 페이지 에 들 어가 면 새로운 struts.token 의 값 이 생 깁 니 다.그러면 사용자 가 제출 하거나 여러 번 제출 하거나 뒤로 물 러 나 다시 제출 하 는 것 을 방지 하고 여러 개의 중복 데이터 가 생 깁 니 다.
2.이 안에 있 는 token 의 생 성
new  BigInteger(165, RANDOM).toString(36).toUpperCase();
 
public static final String DEFAULT_TOKEN_NAME = "struts.token";
 
  public static final String TOKEN_NAME_FIELD = "struts.token.name";

  public static String setToken(String tokenName) {
        Map session = ActionContext.getContext().getSession();
        String token = generateGUID();
        try {
            session.put(tokenName, token);
        }
        catch(IllegalStateException e) {
            // WW-1182 explain to user what the problem is
            String msg = "Error creating HttpSession due response is commited to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: " + e.getMessage();
            LOG.error(msg, e);
            throw new IllegalArgumentException(msg);
        }
        return token;
    }

 
이렇게 하면 여기 밖 에 없어 요.
tokenName 은 변 수 량 입 니 다.그러면 서로 다른 페이지 의 key 가 다 릅 니 다.
한 페이지 에 폼 을 중복 제출 하여 검증 합 니 다.두 페이지 가 동시에 추 가 될 때 모두 기본 값 일 수 없습니다.그렇지 않 으 면 다른 페이지 가 유효 하지 않 습 니 다.
 

좋은 웹페이지 즐겨찾기