zoukankan      html  css  js  c++  java
  • jsp servlet ajax入门删除

    <script type="text/javascript">
    var xmlreq = false;  
    function createXmlHttpRequest()
    {      
        if (window.XMLHttpRequest) {  
            xmlreq = new XMLHttpRequest();    
            } else if (window.ActiveXObject) {
                try {                 
                    xmlreq = new ActiveXObject("Msxml2.XMLHTTP");      
                    } catch (e1) {                                                  
                        try {
                            xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
                            } catch (e2) {      
                                
                            }
                            }
                    }
        return xmlreq;
    }
    
    function del(id){
        var request = createXmlHttpRequest();
        request.open("post","<%=path%>/StuServlet?methodName=delete&id="+id);
        request.send();
        request.onreadystatechange=function(){
            if (xmlreq.readyState == 4)
              {
                if (xmlreq.status == 200)
                {    
                    var check = xmlreq.responseText;  
                    show (check);
    <TD><a href="javascript:void(0)" onclick="del(<%=id%>)">刪除</a></TD>
    

      

      public int delete(int i){
            	Connection conn = new ConnectionUtil().openConnection(); 
            	try{
            		PreparedStatement ps = conn.prepareStatement(DELETE_STUDENT_SQL); 
            		ps.setInt(1,i);
            		ps.executeUpdate();
            		return 1;
            	}catch(SQLException e){
            		e.printStackTrace();
            		
            	}finally{
            		try{
            			conn.close();
            		}catch(SQLException e){
            			e.printStackTrace();
            		}
            	}
    			return 0;
            }
    

      

    private void delete(HttpServletRequest request, HttpServletResponse response) 
    			throws IOException {
    		// TODO Auto-generated method stub
    		int id =Integer.parseInt(request.getParameter("id"));
    		StudentDao dao =new StudentDaoImpl();
    		PrintWriter out = response.getWriter();
    		
    		if(dao.delete(id)==1){
    			out.write("OK");
    		}
    		else{
    			out.write("NO");
    		}
    		//query(request, response);
    		out.close();
    	}
    

      自己硬着头皮做的一个ajax的删除异步刷新

  • 相关阅读:
    Kafka中的数据清理(logdeletion)
    genymotion虚拟器笔记
    layui hover显示图片
    vue 导出到excel
    el-tree知识积累
    js 含有对象的数组去重
    苏宁易购价格爬取(golang)
    vue+elementui+beego笔记
    vue笔记
    beego笔记
  • 原文地址:https://www.cnblogs.com/yanz/p/3866102.html
Copyright © 2011-2022 走看看