jsp页面中,通过点击按钮button调用以下内容
String procedure="{call p_hqdata}";
CallableStatement cstmt = conn.prepareCall(procedure);
cstmt.executeUpdate();
如何把这些代码加入到js中!!

解决方案 »

  1.   

    js中不能加入服务器端代码,要执行服务器端代码,得提交到一另个页面,一般用xmphttp形式,也就是现在常说的ajax。
      

  2.   

    用ajax访问你这段代码,js中还真不知道写这代码
      

  3.   

    ajax:
              var xmlhttp = false;
         try {
             xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
             try {
                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e2) {
                 xmlhttp = false;
             }
         }
         if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
             xmlhttp = new XMLHttpRequest();
         }
    //Ajax函数,向服务器端发送查询
         function Ajax(data){    
           var classtitle=document.getElementById("classtitle");
             xmlhttp.open("GET","跳转地址--后台执行存储过程",true);
             xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
             xmlhttp.send(null);
        
             xmlhttp.onreadystatechange=function(){
                 if (4==xmlhttp.readyState){
                     if (200==xmlhttp.status){
                                     //xmlhttp.responseText  后台返回值(可有可无)
                       if(xmlhttp.responseText==1){
                        document.getElementById("name").innerHTML="此分类基本资料名称已存在!";
                        leaveMesTypeName.value="";
                       }
                       if(xmlhttp.responseText==0){
                        document.getElementById("name").innerHTML="此分类基本资料名称可以使用!";
                       }
                     }else{
                         alert("发生错误!");
                     }
                 }
             }
         }
         
      

  4.   

    js 提交请求 到服务器
    然后服务器java程序处理
    java调用存储过程