Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何使用jsp创建Jqgrid_Json_Jsp_Jqgrid - Fatal编程技术网

Json 如何使用jsp创建Jqgrid

Json 如何使用jsp创建Jqgrid,json,jsp,jqgrid,Json,Jsp,Jqgrid,我对jquery和json非常陌生。我知道jsp和java 在我的项目工作中,我必须实现一个与中所示相同的数据网格 在这个示例站点中,我需要一个使用Json对象的datagrid。 我在互联网上探索所有的东西,但我找不到任何帮助 请给我举一个使用jsp-servlet的jqgrid json的例子,你真的了解了整个互联网吗?给人印象深刻的jqGrid演示页面上的所有演示都显示了必要的代码,甚至包括服务器端代码。您只需将其PHP转换为JSP/Servlet代码。我最终将PHP代码转换为jqgrid

我对jquery和json非常陌生。我知道jsp和java 在我的项目工作中,我必须实现一个与中所示相同的数据网格 在这个示例站点中,我需要一个使用Json对象的datagrid。 我在互联网上探索所有的东西,但我找不到任何帮助


请给我举一个使用jsp-servlet的jqgrid json的例子,你真的了解了整个互联网吗?给人印象深刻的jqGrid演示页面上的所有演示都显示了必要的代码,甚至包括服务器端代码。您只需将其PHP转换为JSP/Servlet代码。

我最终将PHP代码转换为jqgrid的JSP代码:

jQuery(document).ready(function()
    {

    jQuery("#list10").jqGrid({

        url:'griddata.jsp',
    colNames:['Inv No','Date', 'Client'],
        colModel:[{name:'id',index:'id', width:55},{name:'invdate',index:'invdate', width:90},{name:'name',index:'name', width:100}],
    rowNum:10,
    rowList:[5,7,10],
    pager: '#pager10',
    sortname: 'id',
        datatype: 'json',
        viewrecords: true,
        sortorder: "desc",
    multiselect: false,
    imgpath: "themes/basic/images",
    caption: "Invoice Header",
    onSelectRow: function(ids) {

                        jQuery("#list10_d").jqGrid().setGridParam({url : 'getsubdata.jsp?id='+ids}).trigger("reloadGrid")
                        jQuery("#list10_d").jqGrid('setCaption',"Invoice Detail: "+ids)

                        }

        });

    jQuery("#list10").jqGrid('navGrid','#pager10',{add:false,edit:false,del:false});


<!-- subgrid start-->

    jQuery("#list10_d").jqGrid({
                                url:'getsubdata.jsp?id=0',
                                datatype: 'json',
                                colNames:['No','Item', 'Qty', 'Unit','Line Total'],
                                colModel:[
                                        {name:'num',index:'num' },
                                        {name:'item',index:'item'},
                                        {name:'qty',index:'qty',align:"center"},
                                        {name:'unit',index:'unit', align:"center"},     
                                        {name:'linetotal',index:'linetotal',align:"center", sortable:false, search:false}
                                ],
                                rowNum:5,
                                rowList:[5,10,20],
                                pager: '#pager10_d',
                                sortname: 'item',
                                viewrecords: true,
                                sortorder: "asc",
                                multiselect: true,
                                imgpath: "themes/basic/images",
                                caption:"Invoice Detail"
                        }).navGrid('#pager10_d',{add:false,edit:false,del:false});


     }//function
    );//ready
jQuery(文档).ready(函数()
{
jQuery(“#list10”).jqGrid({
url:'griddata.jsp',
colNames:['Inv No','Date','Client'],
colModel:[{name:'id',index:'id',width:55},{name:'invdate',index:'invdate',width:90},{name:'name',index:'name',width:100}],
rowNum:10,
行列表:[5,7,10],
传呼机:“#第10页”,
sortname:'id',
数据类型:“json”,
viewrecords:是的,
巫师:“描述”,
多选:错,
imgpath:“主题/基本/图像”,
标题:“发票抬头”,
OnSetrow:功能(ids){
jQuery(“#list10_d”).jqGrid().setGridParam({url:'getsubdata.jsp?id='+ids}).trigger(“重新加载网格”)
jQuery(“#list10_d”).jqGrid('setCaption',“发票明细:”+id)
}
});
jQuery(“#list10”).jqGrid('navGrid','#pager10',{add:false,edit:false,del:false});
jQuery(“#list10_d”).jqGrid({
url:'getsubdata.jsp?id=0',
数据类型:“json”,
列名称:[“否”、“项目”、“数量”、“单位”、“行总数”],
colModel:[
{名称:'num',索引:'num'},
{名称:'item',索引:'item'},
{名称:'qty',索引:'qty',对齐:“中心”},
{名称:'unit',索引:'unit',对齐:“center”},
{name:'linetotal',index:'linetotal',align:'center',sortable:false,search:false}
],
行数:5,
行列表:[5,10,20],
寻呼机:'#第10页'',
sortname:'项目',
viewrecords:是的,
分拣员:“asc”,
多选:对,
imgpath:“主题/基本/图像”,
标题:“发票明细”
}).navGrid('pager10_d',{add:false,edit:false,del:false});
}//作用
);//准备好的
在这段代码中,我创建了两个jsp文件

第一个代码如下

<%@ page import="java.sql.*,java.util.ArrayList,net.sf.json.*" %>
<%
        String rows=request.getParameter("rows");

        String pageno=request.getParameter("page");
        String cpage=pageno;

        Connection connect = null;
        Statement statement = null;
        PreparedStatement preparedStatement = null;
        ResultSet rs= null;
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connect = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root");
        statement = connect.createStatement();
        rs = statement.executeQuery("SELECT * FROM grid ");

        int count=0;
        rs.last();
        count=rs.getRow(); 

        int  pageval=0;
        pageval=(count/Integer.parseInt(rows));

        int limitstart=0;

        limitstart=(Integer.parseInt(rows)*Integer.parseInt(pageno))-Integer.parseInt(rows);
        int total=count/Integer.parseInt(rows);
        String totalrow=String.valueOf(total+1);

        rs = statement.executeQuery("SELECT * FROM grid limit "+limitstart+","+rows);  


        JSONObject responcedata=new JSONObject();
        net.sf.json.JSONArray cellarray=new net.sf.json.JSONArray();

         responcedata.put("total",totalrow);
        responcedata.put("page",cpage);
        responcedata.put("records",count);

        net.sf.json.JSONArray cell=new net.sf.json.JSONArray();
        net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();

        int i=1;
       while(rs.next())
           {
                cellobj.put("id",rs.getString(1));
                cell.add(rs.getString(1));
                cell.add(rs.getString(2));
                cell.add(rs.getString(3));

        cellobj.put("cell",cell);
        cell.clear();
        cellarray.add(cellobj);
        i++;
       }
        responcedata.put("rows",cellarray);
        out.println(responcedata);

%>
<%@ page import="java.sql.*,java.util.ArrayList,net.sf.json.*" %>
<%
        String id=request.getParameter("id");
        String rows=request.getParameter("rows");
        String pageno=request.getParameter("page");
        String cpage=pageno;


        JSONObject mysubdata=new JSONObject();
        JSONArray subarray = new JSONArray();
        Connection connect = null;
   Statement statement = null;

 ResultSet rs= null;
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connect = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root");
        statement = connect.createStatement();

        rs = statement.executeQuery("SELECT * FROM subgrid where gridid='"+id+"'");  

        int count=0;
        rs.last();
        count=rs.getRow(); 

        int  pageval=0;
        pageval=(count/Integer.parseInt(rows));

        int limitstart=0;

        limitstart=(Integer.parseInt(rows)*Integer.parseInt(pageno))-Integer.parseInt(rows);
        int total=count/Integer.parseInt(rows);
        String totalrow=String.valueOf(total+1);

        rs = statement.executeQuery("SELECT * FROM subgrid where gridid='"+id+"' limit "+limitstart+","+rows);  

        JSONObject responcedata=new JSONObject();
        net.sf.json.JSONArray cellarray=new net.sf.json.JSONArray();

        responcedata.put("total",totalrow);
        responcedata.put("page",cpage);
        responcedata.put("records",count);

        net.sf.json.JSONArray cell=new net.sf.json.JSONArray();
        net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();

        int ii=1;
       while(rs.next()) 

       {
                cellobj.put("id",""+ii);

                //cell.add(rs.getString(1));
                cell.add(rs.getString(1));
                cell.add(rs.getString(2));
                cell.add(rs.getString(3));
                cell.add(rs.getString(4));
                cell.add(rs.getString(4));

        cellobj.put("cell",cell);
        cell.clear();
        cellarray.add(cellobj);
        ii++;
       }
        responcedata.put("rows",cellarray);
        out.println(responcedata);

secound JSP meams getsubdata.JSP文件如下:

<%@ page import="java.sql.*,java.util.ArrayList,net.sf.json.*" %>
<%
        String id=request.getParameter("id");
        String rows=request.getParameter("rows");
        String pageno=request.getParameter("page");
        String cpage=pageno;


        JSONObject mysubdata=new JSONObject();
        JSONArray subarray = new JSONArray();
        Connection connect = null;
   Statement statement = null;

 ResultSet rs= null;
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connect = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root");
        statement = connect.createStatement();

        rs = statement.executeQuery("SELECT * FROM subgrid where gridid='"+id+"'");  

        int count=0;
        rs.last();
        count=rs.getRow(); 

        int  pageval=0;
        pageval=(count/Integer.parseInt(rows));

        int limitstart=0;

        limitstart=(Integer.parseInt(rows)*Integer.parseInt(pageno))-Integer.parseInt(rows);
        int total=count/Integer.parseInt(rows);
        String totalrow=String.valueOf(total+1);

        rs = statement.executeQuery("SELECT * FROM subgrid where gridid='"+id+"' limit "+limitstart+","+rows);  

        JSONObject responcedata=new JSONObject();
        net.sf.json.JSONArray cellarray=new net.sf.json.JSONArray();

        responcedata.put("total",totalrow);
        responcedata.put("page",cpage);
        responcedata.put("records",count);

        net.sf.json.JSONArray cell=new net.sf.json.JSONArray();
        net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();

        int ii=1;
       while(rs.next()) 

       {
                cellobj.put("id",""+ii);

                //cell.add(rs.getString(1));
                cell.add(rs.getString(1));
                cell.add(rs.getString(2));
                cell.add(rs.getString(3));
                cell.add(rs.getString(4));
                cell.add(rs.getString(4));

        cellobj.put("cell",cell);
        cell.clear();
        cellarray.add(cellobj);
        ii++;
       }
        responcedata.put("rows",cellarray);
        out.println(responcedata);


谢谢你的回复。实际上,我在jsp中转换PHP代码时遇到了问题,我知道还有其他部分。如果你帮我转换这个,哈特利很感激。然后你应该在一个新问题中发布你遇到问题的相关代码。或者用更多信息编辑此问题。仍然有人无法获得成功,请告诉我我会帮助他/她谢谢Dhrumil Shahi Dhrumil Shah你能告诉我桌子结构吗?@Rakesh我找不到你。要在网格中显示的DB Table struct.Columns需要什么放在cell.add(rs.getString(1));cell.add(rs.getString(2));cell.add(rs.getString(3));这段代码中还列出了网格列模型的名称。你会得到结果的。我想你明白我的意思了。如果您仍然有问题,请详细询问。