title: Working of Scriptlets in jsp
body: <p>I am working on the maintenance of old project that uses scriptlets in JSP (I know it's not good practice but cann't help it ). The JSP Page contains more than one scriptlets(&lt;% %>) - 
   1. Are these scriptlets processed before bodyonload or before the DOM loads
   2. whether the order of execution of scriptlets will be from top to bottom.
   3. whether scriptlets runs before the script gets loaded</p>
  
  <p>Thanks in advance !</p>
  
  <pre><code> &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ page language="java" contentType="text/html; charset=euc-kr"
      pageEncoding="euc-kr" %&gt;
  
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=euc-kr"&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;style type="text/css"&gt;
  &lt;/style&gt;
  &lt;%
      String ctxPath = request.getContextPath();
      //get goods_name, cus_name from DB
      String goods_name = "»ç°ú 5kg";
      String cus_name = "È«±æµ¿";
  
      String ord_num = request.getParameter("ord_num");
      String carrier_code = request.getParameter("carrier_code");
      String carrier_codeOri = request.getParameter("carrier_codeOri");
      String prodClass = request.getParameter("prodClass");
      String linenumber = request.getParameter("linenumber") == null
                          || "".equals(request.getParameter("linenumber"))
                          ? "0" : request.getParameter("linenumber");
      String orddate = request.getParameter("orddate");
      String ordStatus = request.getParameter("ordStatus");
      String OrderTypeItem = request.getParameter("OrderTypeItem");
      String venderId = request.getParameter("venderId");     
      String callcenter = request.getParameter("callcenter")== null ? "" : request.getParameter("callcenter");
      String Invoice_Num = request.getParameter("invoice_num")== null ? "" : request.getParameter("invoice_num");
      String InvociesNum = Invoice_Num;
      String agent = request.getParameter("agent")== null ? "" : request.getParameter("agent");
  
      String strB2BI_FLAG = "";
  
      //change hanjin furniture express to hanjin express
      if("HF".equals(agent)){
          agent = "HJ";
      }
  
  %&gt;
  
  &lt;script language="javascript"&gt;
      var tid = "";
      function onStart() {
          var InvociesNum = '&lt;%= InvociesNum%&gt;';
  
          if (InvociesNum != ' ') {
              tid=setTimeout(init,0);
          } else {
              if(tid != undefined &amp;&amp; tid != ""){
                  clearTimeout(tid);
              }
              alert("ÅÃ¹è»ç ¿î¼ÛÀå Á¤º¸°¡ ¾ø¾î¼­ ¹è¼ÛÇöÈ²À» Á¦°øÇÒ ¼ö ¾ø½À´Ï´Ù.\n\nÀá½ÃÈÄ ´Ù½Ã ½ÃµµÇØ ÁÖ½Ê½Ã¿À.");
              self.close();
          }
      }
  &lt;/script&gt;
  &lt;%
     String pageUrl = "";    // connection page
     String scriptStr = "";  // call add on script function
  
     // # if 1
      if(InvociesNum != null &amp;&amp; !InvociesNum.equals("")) {  // if has invoice number
                  // #  if 2
                      if( "HJ".equals(agent)) {  
                          pageUrl = ctxPath+"/jsp/jseig_viewGoods.jsp";
  
                      } else if ("DH".equals(agent) || "DZ".equals(agent) || "CV".equals(agentd)) {  
                          pageUrl = ctxPath+"/jsp/jseig_viewGoodsT.jsp";
  
                      // hyundai, CJHTH  , CJGLS  , logen
                      } else if("HD".equals(agent) || "HT".equals(agent) || "CJ".equals(agent) || "KG".equals(agent)) {
                          pageUrl = ctxPath+"/jsp/jseig_viewGoodsTra.jsp";
  
                      // KGB express, yellow cap, dongbu, post office ...
                      } else if( "KL".equals(agent) || "AJ".equals(agent) || "KT".equals(agent) || "KR".equals(agent)
                              || "EP".equals(agent) || "ER".equals(agent) || "YC".equals(agent) || "TR".equals(agent)
                              || "SG".equals(agent) || "FA".equals(agent) || "ND".equals(agent) || "IN".equals(agent)
                              || "DS".equals(agent) || "CI".equals(agent) || "IY".equals(agent) || "KD".equals(agent) ) {
                          pageUrl = ctxPath+"/jsp/jseig_viewGoodsTrackingPHSC2.jsp";
  
                      } else if("DM".equals(agent)) { // dongyang magic
                          pageUrl = "http://www.tymg.co.kr/scripts/wgate/zs84a/!?VBKD-BSTKD_M="+ ord_num+";
                          scriptStr ="window.resizeTo(626,580);";
  
                      }else if("WW".equals(agent)) { //wizwid
                          pageUrl ="http://www.wizwid.com/CSW/handler/wizwid/kr/PopupDeliveryStatus-Start?JID=012861&amp;JOrderID="+ord_num;
                          scriptStr  = "window.resizeTo(650,640);";
  
                      } else {
                          if("3100".equals(carrier_codeOri) &amp;&amp; ("A01".equals(prodClass) || "A03".equals(prodClass) || "A05".equals(prodClass) || "A07".equals(prodClass) || "A11".equals(prodClass) || "A25".equals(prodClass))) {
  
                                  scriptStr ="window.resizeTo(626,580);";
                                  scriptStr += "document.location.replace('"+ctxPath+"/jsp/jseig_viewInstallGoodsInfo.jsp?returnOrdNum="+ord_num+"')";
                          } else {
                                  scriptStr ="document.location.replace('"+ctxPath+"/jsp/viewMyBuy_popup4.jsp')";
                          }
                      }  // # if 2 END
  
          } else {  // have not invoice number
              if ("DM".equals(agent)){    //dongyang magic
                  pageUrl ="http://www.tymg.co.kr/scripts/wgate/zs84a/!?VBKD-BSTKD_M="+ ord_num +"&amp;ITSID=500784&amp;ITSPW=4725";
              }else{
                  if("3100".equals(carrier_codeOri) &amp;&amp; ("A01".equals(prodClass) || "A03".equals(prodClass) || "A05".equals(prodClass) || "A07".equals(prodClass) || "A11".equals(prodClass) || "A25".equals(prodClass))) {
                      scriptStr = "document.location.replace('"+ctxPath+"/jsp/jseig_viewInstallGoodsInfo.jsp?returnOrdNum="+ord_num+"')";
                  } else {
                      scriptStr = "document.location.replace('"+ctxPath+"/jsp/viewMyBuy_popup4.jsp')";
                  }
              } // end if from DM
          } // # if 1 END
  %&gt;
  
  &lt;script language="javascript"&gt;
  
      function init(){
  &lt;%      if( !"GT".equals(agent) ) {
              out.print(scriptStr);
              if(!"".equals(pageUrl) &amp;&amp; pageUrl.length()&gt;0) { out.print("goPage('"+ pageUrl +"');");  }
          } else {
              out.print("window.open("+pageUrl+");");
          } %&gt;
      }
      function goPage(url){
          document.invoiceForm.action = url;
          document.invoiceForm.submit();
      }
  
  
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body onload="onStart()"&gt;
  &lt;form name="invoiceForm" method="post"&gt;
    &lt;input type="hidden" name="invoiceNum" value="&lt;%= InvociesNum %&gt;"&gt;
    &lt;input type="hidden" name="invoice_num" value="&lt;%= InvociesNum %&gt;"&gt;
    &lt;input type="hidden" name="ord_num" value="&lt;%= ord_num %&gt;"&gt;
    &lt;input type="hidden" name="goods_name" value="&lt;%= goods_name %&gt;"&gt;
    &lt;input type="hidden" name="cus_name" value="&lt;%= cus_name %&gt;"&gt;
    &lt;input type="hidden" name="agent" value="&lt;%= agent %&gt;"&gt;
    &lt;input type="hidden" name="reqFlag" value="Y"&gt;
    &lt;input type="hidden" name="ordNum" value="&lt;%= ord_num %&gt;"&gt;
    &lt;input type="hidden" name="lineNum" value="&lt;%= linenumber %&gt;"&gt;
  &lt;%
    session.setAttribute("callcenter", callcenter);
  %&gt;
  &lt;/form&gt;
  &lt;div style="height:600" align="center" valign="center"&gt;Ã³¸®ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á fgfg.&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>