problem with server-side

problem with server-side

rang3rang3 Posts: 3Questions: 0Answers: 0
edited July 2010 in General
Hi all,
i write applications and using this plugin. I write server-side script like an example.
[code]
<%
JSONObject result=new JSONObject();
JSONArray array= new JSONArray();

int amount=10;
int start=0;
int echo=0;
int col=0;

String dir = "asc";
String sStart = request.getParameter("iDisplayStart");
String sAmount = request.getParameter("iDisplayLength");
String sEcho = request.getParameter("sEcho");
String sCol = request.getParameter("iSortCol_0");
String sdir = request.getParameter("sSortDir_0");

if(sStart!=null)
{
start=Integer.parseInt(sStart);
if(start<0)
start=0;
}
if(sAmount!=null)
{
amount=Integer.parseInt(sAmount);
if(amount<10||amount>100)
amount=10;
}
if(sEcho!=null)
echo= Integer.parseInt(sEcho);

if(sCol!=null)
{
col= Integer.parseInt(sCol);
if(col<0||col>1)
col=1;
}
if(sdir!=null)
{
if(!sdir.equals("asc"))
dir="desc";
}
String colName="Rendering engine";
String searchTerm = request.getParameter("sSearch");
String searchString=request.getParameter("search");
Collection collection= Manager.getInstance().getMessagesContainsSubStringFromTo(searchString,start,start+amount);
for(ParentObject mess:collection)
{
JSONArray ja=new JSONArray();
ja.put(mess.getName()+((Message)mess).getBody());
array.put(ja);
}
result.put("iTotalRecords",collection.size());
result.put("iTotalDisplayRecords",collection.size());
result.put("sEcho",echo);
result.put("aaData",array);

response.setContentType("application/json");
response.setHeader("Cache-Control", "no-store");
try
{
response.getWriter().print(result);
}
catch (IOException e)
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}

%>
[/code]
This jsp on my opinion must generate JSON data for display on other jsp where located the table.
Following code its jsp with table and script for init
[code]
<%@ page contentType="text/html;charset=UTF-8" language="java" %>



Simple jsp page




@import "js/dataTables-1.6/media/css/demo_table.css";
@import "js/dataTables-1.6/media/css/demo_table_jui.css";
@import "js/jquery-ui-1.8.2.custom/css/ui-darkness/jquery-ui-1.8.2.custom.css";

$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "resultSearch.jsp",
"fnServerData": function(sSource, aoData, fnCallback)
{
aoData.push ({ "name":"search", "value": "55#" });
$.ajax(
{
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback

});
},
"bJQueryUI": true
} );
} );








Rendering engine





Loading data from server




Rendering engine








[/code]
After loading jsp i have 1 row with string "Loading data from server". And all.
Help me please with my problem.
thank you, sorry for my English

Replies

  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    Usse firefox to verify that you are sending a request to the server. Of that is happening, verify that the json returned is valid. Use jsonlint.com
  • rang3rang3 Posts: 3Questions: 0Answers: 0
    edited July 2010
    i testing this scipt on jsp and servlets, answer from server returned and his looks like on following code(in this example i not use request, simply generated json object)
    [code]
    {"iTotalDisplayRecords":10,"iTotalRecords":10,"aaData":[["955#"],["755#"],["855#"],["455#"],["555#"],["655#"],["255#"],["355#"],["155#"],["55#"]],"sEcho":3}
    [/code]
    This json object was generated on following jsp(or servlets code, i dont think what use better)
    [code]
    <%
    JSONObject result=new JSONObject();
    JSONArray array= new JSONArray();

    int amount=15;
    int start=0;
    int echo=3;
    int col=0;

    String dir = "asc";
    /*String sStart = request.getParameter("iDisplayStart");
    String sAmount = request.getParameter("iDisplayLength");
    String sEcho = request.getParameter("sEcho");
    String sCol = request.getParameter("iSortCol_0");
    String sdir = request.getParameter("sSortDir_0");
    */
    /*if(sStart!=null)
    {
    start=Integer.parseInt(sStart);
    if(start<0)
    start=0;
    }
    if(sAmount!=null)
    {
    amount=Integer.parseInt(sAmount);
    if(amount<10||amount>100)
    amount=10;
    }
    if(sEcho!=null)
    echo= Integer.parseInt(sEcho);

    if(sCol!=null)
    {
    col= Integer.parseInt(sCol);
    if(col<0||col>1)
    col=1;
    }
    if(sdir!=null)
    {
    if(!sdir.equals("asc"))
    dir="desc";
    }*/
    String colName="Rendering engine";
    /*String searchTerm = request.getParameter("sSearch");
    String searchString=request.getParameter("search");
    */Collection collection= Manager.getInstance().getTopicContainsSubString("55#");
    for(ParentObject mess:collection)
    {
    JSONArray ja=new JSONArray();
    ja.put(mess.getName());
    array.put(ja);
    }
    result.put("iTotalRecords",collection.size());
    result.put("iTotalDisplayRecords",collection.size());
    result.put("sEcho",echo);
    result.put("aaData",array);
    out.print(result.toString());
    %>
    [/code]
    may be problem in init table ?
  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    You might want to check the FAQ. It specifically states that that you must return the the sEcho value that the client sent back from the server. This maintains the synchronization of requests. If two sequential requests get sent from the client and the first request is actually processed and sent back after the second request, datatables will not process it due to it being older. sEcho identifies the sequence of requests.
  • rang3rang3 Posts: 3Questions: 0Answers: 0
    Thank you, for ypur comment. I understand with my problem, but i dont understand the difference between following string:
    [code]
    "sAjaxSource": "resultSearch.jsp",
    [/code]
    and
    [code]
    "sAjaxSource": "http://localhost:9090/forum/resultSearch.jsp",
    [/code]
    With first string not work, but with second string is working.
  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    Try "forum/resultSearch.jsp"

    Since I don't know how jsp server works for running from root directory.
This discussion has been closed.