Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Struts
JSON JQuery Grid Not getting value in JSP
Nagu Spartan
Ranch Hand
Posts: 40
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I have problem to get the Json value in
jsp
page.
struts
2 framework
struts.xml
<action name="json-table" class="com.JsonTableAction"> <result type="json">/home.jsp</result> </action>
home.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="org.json.simple.JSONObject"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <link rel="stylesheet" type="text/css" media="screen" href="themes/redmond/jquery-ui-1.8.2.custom.css" /> <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" /> <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.multiselect.css" /> <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script> <script src="js/jquery.layout.js" type="text/javascript"></script> <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script> <script type="text/javascript"> $.jgrid.no_legacy_api = true; $.jgrid.useJSON = true; </script> <script src="js/ui.multiselect.js" type="text/javascript"></script> <script src="js/jquery.jqGrid.js" type="text/javascript"></script> <script type="text/javascript"> jQuery().ready(function (){ /*$.ajax({ type: "GET", url: "json-table", success:function(data) { alert("Here --------- success " + data ); }, error:function(data) { alert("Here --------- error"); } });*/ jQuery("#list2").jqGrid({ url:'json-table', datatype: "json", colNames:['Name','Description'], colModel:[ {cell:'name',index:'name', width:90}, {cell:'description',index:'description', width:90} ], rowNum:20, rowList:[5,10,20,30], pager: '#pager2', sortname: 'id', viewrecords: true, sortorder: "desc", caption:"JSON Example" }); jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false}); }); </script> </head> <body> <table id="list2"></table> <div id="pager2"> </div> </body> </html>
JsonTableAction.java
package com; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import flexjson.JSONSerializer; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class JsonTableAction extends ActionSupport { public String execute() { System.out.println("--------------- execute()"); List<Color> colors = new ArrayList<Color>(); Color c1 = new Color(); c1.setId(1); c1.setName("n1"); c1.setDescription("d1"); Color c2 = new Color(); c2.setId(2); c2.setName("n2"); c2.setDescription("d2"); colors.add(c1); colors.add(c2); JQGridJSONModel json = new JQGridJSONModel(); json.setPage("1"); json.setRecords(colors.size()); json.setTotal("1"); List<JQGridRow> rows = new ArrayList<JQGridRow>(); for (Color c : colors) { JQGridRow row = new JQGridRow(); row.setId(c.getId()); List<String> cells = new ArrayList<String>(); cells.add(c.getName()); cells.add(c.getDescription()); row.setCell(cells); rows.add(row); } json.setRows(rows); JSONSerializer serializer = new JSONSerializer(); // ((Object) serializer).exclude( "*.class" ); String jsonResult = serializer.exclude("*.class").deepSerialize(json); System.out.println("Resultado = " + jsonResult); return SUCCESS; } }
Console , I am getting the output but i can't able to get the result in jsp page grid
--------------- execute() Resultado = {"page":"1","records":2,"rows":[{"cell":["n1","d1"],"id":1},{"cell":["n2","d2"],"id":2}],"total":"1"}
Can anyone please tell the solution for this problem
Thanks & Regards,
Nagarajan T.
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
values are not populated in browser
Error DefaultActionInvocation
Is it possible to put a button inside autocomplete in jquery ui plugin?
Directory Structure JSP & JS
jQuery datepicker JSP question
More...