2016-06-17 2 views
0

jsp에서 작업 중입니다. 구현하려는 것은 매우 간단합니다.jsp : 렌더/실행 순서를 바꿀 수 있습니까?

  • 자바 약간의 시간이 소요되는 작업을 할
  • 그러나
    <%@ page contentType="text/html; charset=UTF-8" %> 
    <%@ page isThreadSafe="true" %> 
    <% 
    
        boolean isFinish = false; 
        Thread executeThread = new Thread(new Runnable() { 
         @Override 
         public void run() { 
          for(int i = 0; i < 10; i++){ 
           try{ 
            System.out.println(i + " Thread "); 
            Thread.sleep(1000); 
           }catch(Exception ex){ 
            System.err.println(ex); 
           } 
          } 
         } 
        }); 
    
        executeThread.run(); 
    %> 
    <!DOCTYPE html> 
    <html> 
        <head> 
         <meta charset='utf-8'> 
         <title>Loading</title> 
        </head> 
        <body> 
         <div class="popup" style="text-align: center;"> 
          <div class="l_img"> 
           <img src="resources/image/spinner/loading_gif.gif" alt="LOADING..."> 
          </div> 
          <div class="b_txt">Processing</div> 
          <div class="s_txt">Please, wait..</div> 
         </div> 
        </body> 
        <% 
         if(isFinish){ 
        %> 
         <script> 
          alert('done'); 
         </script> 
        <% 
         } 
        %> 
    </html> 
    

    아래 처리, 쇼 사용자

그래서 나는 다음과 같이 구현 한 회가, 페이지를 스레드 후 표시하면서 종료되었습니다. 주문을 취소 할 수 있습니까? 나는 (spinner gif)

  • 자바 로직을
  • 캐치 자바 실행의 반환을 실행하기

    • 쇼 HTML 페이지를 원하는 무엇
    • 수익률은 자바 스크립트
    에 다음 경고 true 인 경우

    가능합니까? 답변 해 주셔서 감사합니다.

  • 답변

    1

    서버 측 작업을 대체하여 페이지를 동적으로 변경할 수 없습니다.

    페이지는 항상 if(isFinish)이 실행 된 곳에서 렌더링됩니다.

    서버는 모든 자바가 실행되고 하나의 블록에있을 때만 완전한 HTML 페이지를 사용자에게 보냅니다! 프론트 엔드에서 구현해야합니다. 예를 들어 시작 기본 페이지를로드하고 Ajax 호출 또는 이와 유사한 것으로 장기 프로세스를 호출하는 경우가 있습니다.

    +0

    답장을 보내 주셔서 감사합니다. 나는'Thread'로 구현했기 때문에 Thread가 실행 중인지 아닌지를 보여 주어야한다고 생각했습니다. 그러나 나는 10을 세고 순서대로 페이지를 보여준다. (나는 당신의 포인트 프론트 엔드 처리를 얻었지만 나의 경우에는 그렇게 될 수 없다) 다른 옵션이 있는가? –

    0
    <!DOCTYPE html> 
    <html> 
    <body onload="alert('done')"> 
        Put your spinner here. 
        Some text here is necessary here for the browser to start displaying. 
        Otherwise it will wait until it receives enough of a response to begin displaying anything. 
        I am not sure how much is necessary. This works for me. 
    <% 
        out.print("<br/>Starting processing now. <br/>"); 
        out.flush(); 
        Thread.sleep(2000); 
        out.print("<br/>Processing..... <br/>"); 
        out.flush(); 
        for(int x = 1; x < 4; x++){ 
         Thread.sleep(2000); 
         out.print("Result " + x + ".<br/>"); 
         out.flush(); 
        } 
    %> 
    </body> 
    </html> 
    
    +0

    답변 해 주셔서 감사합니다. 그것은 작동합니다. 그러나 기본적으로 서버 측 스크립트 순서를 제어 할 수는 없습니다. 그래서 나는 다른 대답을 골랐다. 그래도 고마워 –

    관련 문제