jquery jsp 删除和修改。

wenwen1 发布于 2012/08/25 12:29
阅读 795
收藏 0

我写的getCashList1.js如下:

$(function(){
            $('#xmhk').datagrid({
                url:'../json/getCashList.jsp',
                iconCls:'icon-save',
                nowrap: false,
                striped: true,
                collapsible:true,
                remoteSort: false,
                fitColumns: true,
                sortName: 'hkrq',
                sortOrder: 'desc',
                idField:'xmmc',
                pagination:true,//可分页
                loadMsg:"数据加载中....",
                rownumbers:true,
                columns:[[
                    {field:'ck',checkbox:true},
                    {title:"编号",field:'id',hidden:true},
                    {title:'项目名称',field:'xmmc',width:150,sortable:true},
                    {title:'回款日期',field:'hkrq',width:440,sortable:true},
                    {title:'回款金额',field:'hkje',width:80,sortable:true},
                    {title:'回款方式',field:'hkfs',width:200,sortable:true},
                    {title:'回款人',field:'hkr',width:200,sortable:true},
                    {title:'说明',field:'sm',width:200,sortable:true},
                ]],
//-----------------------------------选中进行删除和修改---------------------------------
                toolbar : [//工具栏上定义按钮                          
                           {text:'全部',
                            iconCls:'icon-ok',
                            handler:function(){
                            $('#xmhk').datagrid({url:'../json/getCashList.jsp'});
                              }},'-',{
                                  text:'添加',
                                  iconCls:'icon-add',
                                  handler:function(){window.location='../jsp/newCash.jsp'}
                                 },'-',{
                                id:'btnedit',
                                text:'修改',
                                iconCls:'icon-edit',
                                handler:function(){
                                    getSelect();}
                            },'-',{ id:'btndel',
                                text:'删除',
                                iconCls:'icon-remove',
                                handler:function(){
                                //删除选择的记录
                                delCash();
                                }}]
            });
//-------------------------------------分页定义------------------------------------
            var p = $('#xmhk').datagrid('getPager');
            $(p).pagination({       
                pageSize: 20,//每页显示的记录条数
                pageList: [20,30,40],//可以设置每页记录条数的列表
                beforePageText: '第',//页数文本框前显示的汉字
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示{from}条到{to}条记录   共{total}条记录'
        });
//------------------------------删除事件delCash---------------------------------
            function delCash(){               
                  //得到选中行数据
                 var selected = $('#xmhk').datagrid('getSelected');
                 if(selected){
                  $.messager.confirm('warning','确认删除么?',function(id){
                  if(id){
                      id = selected.id;
                   $.ajax({
                           type:"POST",
                           url:"../jsp/deleteCash.jsp",
                           data:"id="+id,
                           dataType:"json",
                           success:function callback(){}
                        });
                   $('#xmhk').datagrid('reload');
                  }
                 });
                 }else{
                  $.messager.alert('warning','请选择一行数据','warning');
                 }
               $('#xmhk').datagrid({
                    url:'../json/getCashList.jsp',
                    loadMsg:'更新数据......'
                   });
                }
    });       
//--------------------------------修改窗体-------------------------------------
function close1(){
       $('#edit').window('close');
      }
//----------------------------修改 事件editCash----------------------------------
var id;
function getSelect(){
   var select = $('#xmhk').datagrid('getSelected');
   if(select){
    $('#edit').window('open');
    $('#ff').show();
    $('#ff').appendTo('#ee');
    $('#xmmc').val(select.xmmc);
    $('#hkrq').val(select.hkrq);
    $('#hkje').val(select.hkje);
    $('#hkfs').val(select.hkfs);
    $('#hkr').val(select.hkr);
    $('#sm').val(select.sm);
    id = select.id;
   }else{
    $.messager.alert('warning','请选择一行数据','warning');
   }
  }
function edit(){
    var select = $('#xmhk').datagrid('getSelected');
    id = select.id;
$('#ff').form('submit',{
url: '../jsp/updateCashSub.jsp?id='+id,
onSubmit:function(){ return $('#ff').form('validate');},
   success:function(){
     $.messager.alert('edit','修改信息成功!!!','info');
     close1();
    }
});
$('#xmhk').datagrid({
url:'../json/getCashList.jsp',
loadMsg:'更新数据......'
});                  
}

我的cash1.jsp如下:

<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
<%@ page session="true" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="../../jquery/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../jquery/themes/icon.css">   
    <script type="text/javascript" src="../../jquery/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../../jquery/js/jquery.easyui.min.js"></script>   
    <script type="text/javascript" src="../../jquery/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/getCashList1.js"></script>
    <title>项目回款</title>
 </head>
 <%@ include file="../../myfilters.jsp" %>  
 <%
 request.setCharacterEncoding("utf-8");//处理乱码
 String bkeyword = request.getParameter("keywordmc");
 %>
  <body>
   <table id="xmhk"></table>
     <form id="ff" method="post" action="updateCashSub.jsp">
     <div>
               项目名称:<input class="easyui-validatebox" style="width:300;height:30" type="text" id="xmmc" name="xmmc" required="true" disabled/>
    </div>
     <div>
              回款金额:<input class="easyui-numberbox" value="0.00" style="width:300;height:30" type="text" id="hkje" name="hkje" required="true"></input>
     </div><br/>
     <div>
            回款日期:<input class="easyui-datebox"  style="width:300;height:30" id="hkrq" name="hkrq" required="true"></input>
     </div><br/>
     <div>
            回款方式:<input class="easyui-validatebox" style="width:300;height:30" type="text" id="hkfs" name="hkfs" required="true"/></input></div><br/>
     <div>
     &nbsp;&nbsp;回款人:<input class="easyui-validatebox" style="width:300;height:30" type="text" id="hkr" name="hkr" required="true"/></input>
     </div>
     <div>
     &nbsp;&nbsp;&nbsp;&nbsp;说明:<input class="easyui-validatebox" style="width:300;height:30" type="text" id="sm" name="sm"/></input>
     </div>
   </form>
      <div id="edit" class="easyui-window" title="修改" style="padding: 10px;width: 500;height: 300;"
           iconCls="icon-edit" closed="true" maximizable="false" minimizable="false" collapsible="false">
     <div id="ee"></div>
     <a class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" onclick="edit()">修改</a>
     <a class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)" onclick="close1()">取消</a>
     </div>
  </body>
</html>

我写的updateCashSub.jsp如下

<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
<jsp:useBean id="systemRelated" class="net.gvsun.database.SystemRelated"/>
<jsp:useBean id="dbConn" class="pack_convert.DBConnXmgl"/>
<%@ page session="true" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
    <title>updateCashSub</title>

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  <%
  request.setCharacterEncoding("utf-8");//处理乱码
  String id = request.getParameter("20");
  out.print(20);
  //int aid = Integer.parseInt(id);
  String hkrq = request.getParameter("hkrq");
  String hkje = request.getParameter("hkje");
  String hkfs = request.getParameter("hkfs");
  String hkr = request.getParameter("hkr");
  out.print(hkr);
  String sm = request.getParameter("sm");
  String editedBy = (String)session.getAttribute("userName");
  String editedOn =systemRelated.getDateTimeNow();
  String sql = "update project_cash set hkrq='"+hkrq+"',hkje='"+hkje+"',hkfs='"+hkfs+"',hkr='"+hkr+"',sm='"+sm+"',editedBy='"+editedBy+"',editedOn='"+editedOn+"' where idproject_cash="+id;
  boolean bol = dbConn.Sql(sql);
  if(bol){
       out.println("修改成功!");
   }else{
       out.println("出错了,请重新操作!");
   }
  dbConn.releaseConn();//释放链接
  response.setHeader("Refresh","1; URL=../../projectFinance.jsp");//1秒后自动跳转页面

  %>
  <body>
  
  </body>
</html>
我写的deleteCash.jsp如下:

<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="utf-8"%>
<jsp:useBean id="dbConn" class="pack_convert.DBConnXmgl"/>

<%@ page session="true" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <%
 String id = request.getParameter("id");
String sql = "delete from project_cash where idproject_cash="+id;
    boolean bol = dbConn.Sql(sql);
      if(bol){
           out.println("{\"success\":\"true\",\"msg\":\"添加成功!\"}");
     }else{
           out.println("{\"failure\":\"failure\",\"msg\":\"出错了,请重新操作!\"}");
     }
 response.setHeader("Refresh","1; URL=../../projectFinance.jsp");//1秒后自动跳转页面
 //out.println(bol);//打印结果
 dbConn.releaseConn();
 %>

为什么点修改按钮之后它会弹出来修改信息成功,但是页面上还是没修改,我在我的页面中的updateCashSub.jsp中加了一句话out.print(hkrq);然后在tomcat中运行update.jsp,就显示NUll,修改成功
点删除按钮时不能删除,我在tomcat中运行deleteCash.jsp总是弹出出错了,请重新操作!

加载中
0
wenwen1
wenwen1
还出现以下错误:java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.ResultSet.getDateFromString(ResultSet.java:2048)
    at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5732)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5544)
    at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:149)
    at pack_convert.Convert.getMap(Convert.java:59)
    at pack_convert.Convert.getConResult(Convert.java:88)
    at net.gvsun.database.ProjectInfo.getCashList(ProjectInfo.java:51)
    at org.apache.jsp.projectinfo.json.getCashList_jsp._jspService(getCashList_jsp.java:70)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)

0
xiaoyang0878
xiaoyang0878

1、为什么点修改按钮之后它会弹出来修改信息成功,但是页面上还是没修改

     updateCashSub.jsp这个里面就是执行一个sql,进 “修改”进去肯定显示修改成功啊(因为id是对的);

2、点删除按钮时不能删除,我在tomcat中运行deleteCash.jsp总是弹出出错了,请重新操作
    这个你打个断点看看吧。jsp里面没看出什么明显的错误。





返回顶部
顶部