在onload函数

时间:2016-02-10 18:49:00

标签: jsp session servlets

我试图在servlet调用之后创建一个警告框,具体取决于我的一个输入字段“UpdCMDStatus”中的值。看来我需要将它放在我的JSP程序的onload事件中(如果错误则纠正我)。这是我在HTML结尾处的脚本函数调用

           window.onload = confirmProcess;

           function confirmProcess()
              {

                var statusCheck = $('#UpdCMDStatus').val();
                alert("Status Check pulled is " + statusCheck );

                if (statusCheck === "CP" || statusCheck === "RP")
                {
                    var modifymode = $('#RecordFlag').val();
                    alert ("Modify Mode flag is " + modifymode) ;
                    if (modifymode === "Y")
                    {
                       alert("Schedule Numbers for Status 'VP' and 'CP' cannot " +
                                   " be Updated")    ;

                    }
                    else
                    {
                      var modifymode = $('#RecordFlag').val();
                      alert ("Modify Mode flag if status is not CP/RP is " + modifymode) ;  

                   }

               }


           }     ;

以下是我在EFTscreen servlet中对此#RecordFlag会话变量的处理:

   if (action.matches("searchMEFTS"))
    {
        System.out.println("Entering the process to go to MEFTS screen.  Continue");
        session.setAttribute("RecordFlag", " ");

        if (screenaccess.matches("mainEFT"))
        {
           String startStatus = "NP" ;
           session.setAttribute("UpdCMDStatus", startStatus);



           session.setAttribute("UpdCMDCreationDate", CMDcurrentdate);

           wkStatus = startStatus; 


        }
        else
        {    

           wkStatus = request.getParameter("UpdCMDStatus");
           session.setAttribute("UpdCMDStatus", wkStatus);

           wkCreation = request.getParameter("UpdCMDCreationDate");
           session.setAttribute("UpdCMDCreationDate", wkCreation);
           session.setAttribute("RecordFlag", "Y");

        }


       Sum_EFTBean meftsResults = new Sum_EFTBean() ;
       List<Sum_EFTBean> Updresults ; 
       Updresults = EFTQuery.selectDates(wkStatus, wkCreation) ;
       numberOfEntries = Updresults.size() ; 
       url = "/updatesched.jsp";

       if (numberOfEntries == 0) 
         {
           message = ("No open EFT Schedule Numbers found") ;
           session.setAttribute("messageMEFS",message) ;

         }
       else      
        {    
         session.setAttribute("Updresults", Updresults);


        } 

    } 

在检查modifymode字段的alert语句中,它显示为undefined。使用会话变量的问题是由于加载事件还是您看到任何其他问题?

由于

1 个答案:

答案 0 :(得分:0)

请注意,提交表单后,所有输入字段都将被重置(清除)。当然,在您的servlet中,您可以创建一个属性showAlert并将其设置为请求属性。

boolean showAlert = request.getParameter("updCMDStatus").equals("someValue") ?true:false;
request.setAttribute("showAlert", showAlert)

然后在您的java脚本中,您只需编写

function confirmProcess(){

  if( ${showAlert} )//this EL expression will be replaced by either true or false
    //do something
}