在jsp中使用Scriptlet

时间:2014-04-21 18:14:23

标签: java jsp servlets jsp-tags

我正在努力维护在JSP中使用scriptlet的旧项目(我知道这不是一个好习惯但不能帮助它)。 JSP页面包含多个scriptlet(< %%>) -  1.这些scriptlet是在bodyonload之前还是在DOM加载之前处理的  2. scriptlet的执行顺序是从上到下。  3.脚本是否在脚本加载之前运行

提前致谢!

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=euc-kr"
    pageEncoding="euc-kr" %>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title></title>
<style type="text/css">
</style>
<%
    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";
    }

%>

<script language="javascript">
    var tid = "";
    function onStart() {
        var InvociesNum = '<%= InvociesNum%>';

        if (InvociesNum != ' ') {
            tid=setTimeout(init,0);
        } else {
            if(tid != undefined && tid != ""){
                clearTimeout(tid);
            }
            alert("Åùè»ç ¿î¼ÛÀå Á¤º¸°¡ ¾ø¾î¼­ ¹è¼ÛÇöȲÀ» Á¦°øÇÒ ¼ö ¾ø½À´Ï´Ù.\n\nÀá½ÃÈÄ ´Ù½Ã ½ÃµµÇØ ÁֽʽÿÀ.");
            self.close();
        }
    }
</script>
<%
   String pageUrl = "";    // connection page
   String scriptStr = "";  // call add on script function

   // # if 1
    if(InvociesNum != null && !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&JOrderID="+ord_num;
                        scriptStr  = "window.resizeTo(650,640);";

                    } else {
                        if("3100".equals(carrier_codeOri) && ("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 +"&ITSID=500784&ITSPW=4725";
            }else{
                if("3100".equals(carrier_codeOri) && ("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
%>

<script language="javascript">

    function init(){
<%      if( !"GT".equals(agent) ) {
            out.print(scriptStr);
            if(!"".equals(pageUrl) && pageUrl.length()>0) { out.print("goPage('"+ pageUrl +"');");  }
        } else {
            out.print("window.open("+pageUrl+");");
        } %>
    }
    function goPage(url){
        document.invoiceForm.action = url;
        document.invoiceForm.submit();
    }


</script>
</head>

<body onload="onStart()">
<form name="invoiceForm" method="post">
  <input type="hidden" name="invoiceNum" value="<%= InvociesNum %>">
  <input type="hidden" name="invoice_num" value="<%= InvociesNum %>">
  <input type="hidden" name="ord_num" value="<%= ord_num %>">
  <input type="hidden" name="goods_name" value="<%= goods_name %>">
  <input type="hidden" name="cus_name" value="<%= cus_name %>">
  <input type="hidden" name="agent" value="<%= agent %>">
  <input type="hidden" name="reqFlag" value="Y">
  <input type="hidden" name="ordNum" value="<%= ord_num %>">
  <input type="hidden" name="lineNum" value="<%= linenumber %>">
<%
  session.setAttribute("callcenter", callcenter);
%>
</form>
<div style="height:600" align="center" valign="center">ó¸®ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á fgfg.</div>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

在浏览器发生任何事情之前,处理scriplet。它们是服务器端功能,一旦内容到达浏览器,就不会留下任何痕迹(好吧,没有明确的跟踪)。执行顺序从上到下,但scriptlet中的Java代码可以包含控制流指令。