problem with server-side
problem with server-side
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
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
This discussion has been closed.
Replies
[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 ?
[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.
Since I don't know how jsp server works for running from root directory.