jquery - function select2() lost after forward from servlet -


i using bootstrap2.3.2 , select2 3.4.2 in jsp file. want override bootstrap select style select2 library. works when jsp file loaded in first time, after submitting selection servlet , forward same jsp servlet, found function select2() of select object has lost, , select box change bootstrap style. looks select2.js has no effect, why that? please help.

following code snippet

selectcategory.jsp:

            <script src="<%=request.getcontextpath()%>/util/jquery/jquery-1.9.1.js"> </script>             <!-- bootstrap -->             <%              //cannot include bootstrap.css twice             boolean hasbootstrap = (boolean)request.getattribute("hasbootstrap");             if (hasbootstrap == null) {             %>                 <link rel="stylesheet" href=" <%=request.getcontextpath()%>/util/bootstrap2.3.2/css/bootstrap.css" />                 <link rel="stylesheet" href=" <%=request.getcontextpath()%>/util/bootstrap2.3.2/css/bootstrap-select.css" />                 <style type="text/css">                     body {                         padding-top: 60px;                         padding-bottom: 40px;                     }                 </style>                 <link rel="stylesheet" href="<%=request.getcontextpath()%>/util/bootstrap2.3.2/css/bootstrap-responsive.css" />                 <script src="<%=request.getcontextpath()%>/util/bootstrap2.3.2/js/bootstrap-select.js"> </script>                 <script src=" <%=request.getcontextpath()%>/util/bootstrap2.3.2/js/bootstrap.js"> </script>         <%                 hasbootstrap = true;                 request.setattribute("hasbootstrap", hasbootstrap);             } //end of if         %>          <link rel="stylesheet" href="<%=request.getcontextpath()%>/util/jquery/select2-3.4.2/select2.css" />         <script src="<%=request.getcontextpath()%>/util/jquery/select2-3.4.2/select2.js"> </script>      <script>     $(function () {         //$('.selectpicker').selectpicker();         var sel = $('.selectpicker');         var sel2 = $('#selectcat');         $('#selectcat').select2();     });     </script>  <body>     ...           <select class="selectpicker" id="selectcat" name="selectcat" onchange="getsubject()"> 

servlet:

string url = "/standard/selectcategory.jsp"; requestdispatcher successview = req.getrequestdispatcher(url); successview.forward(req, res); 

my problem why $('#selectcat').select2() lost when request forwarded servlet?


update:

look root cause include jquery library twice

because include jsp render query result, , jsp need use tablesorter, include jquery , tablesorter library here. think second included jquery library has effect on select2 library included previously, select2() lost. after remove duplicate included library, result fine.

but did experiment, result seems not expect

file1.jsp:

<link rel="stylesheet" href="<%=request.getcontextpath()%>/util/jquery/tablesorter/style.css" /> <script src="<%=request.getcontextpath()%>/util/jquery/jquery-1.9.1.js"> </script> <script src="<%=request.getcontextpath()%>/util/jquery/tablesorter/jquery.tablesorter.js"> </script> <link rel="stylesheet" href="<%=request.getcontextpath()%>/util/jquery/select2-3.4.2/select2.css" /> <script src="<%=request.getcontextpath()%>/util/jquery/select2-3.4.2/select2.js"> </script>  ...              <div class="secondary">                 <%if (request.getattribute("liststandard") != null) {%>                     <jsp:include page="file2.jsp"/>                 <%} %>             </div> 

file2.jsp

<link rel="stylesheet" href="<%=request.getcontextpath()%>/util/jquery/tablesorter/style.css" /> <script src="<%=request.getcontextpath()%>/util/jquery/jquery-1.9.1.js"> </script> <script src="<%=request.getcontextpath()%>/util/jquery/tablesorter/jquery.tablesorter.js"> </script> <link rel="stylesheet" href="<%=request.getcontextpath()%>/util/jquery/select2-3.4.2/select2.css" /> <script src="<%=request.getcontextpath()%>/util/jquery/select2-3.4.2/select2.js"> </script> 

i thought second included select2.js in file2.jsp should take effect, doesn't


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -