<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: How do I access JSON string in jsp?</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>aarati on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p21553</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p21553</guid>
        	        	<description><![CDATA[<p>Hi Tony,</p>
</p>
<p>I have a similar issue as mentioned in the discussion above. Making use of the following&#160;in the&#160;application:</p>
<p>1) Struts 1.2</p>
<p>2) JQGrid 3.8.2</p>
<p>3) JQuery 1.4.4</p>
</p>
<p>The Struts action method returns a json object after obtaining data from the database. See code below:</p>
<p><em>public ActionForward getJSONData(ActionMapping mapping, ActionForm form,<br />&#160;&#160;&#160;HttpServletRequest request, HttpServletResponse response) {</em></p>
<p><em>...<br />...<br />&#160;JSONObject jsonObj = createJSONTestData();<br />&#160;response.setHeader("X-JSON", jsonObj.toString());<br />&#160;System.out.println("Final JSON OBj: " + jsonObj.toString());<br />&#160;return mapping.findForward(sForward);<br />}</em></p>
<p><em>/*<br />&#160; *This piece of code is the same as the php code mentioned in one of the examples<br />&#160; *provided in jqgrid demos<br />*/<br />public JSONObject createJSONTestData() {<br />....<br />....<br />//Hit the database and obtain the resultset and create the json object</em></p>
<p><em>&#160;JSONObject responcedata=new JSONObject();<br />&#160;net.sf.json.JSONArray cellarray=new net.sf.json.JSONArray();<br />&#160;responcedata.put("total","3");<br />&#160;responcedata.put("page",cpage);<br />&#160;responcedata.put("records","2");</em></p>
<p><em>&#160;net.sf.json.JSONArray cell=new net.sf.json.JSONArray();<br />&#160;net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();</em></p>
<p><em>&#160;int i=1;<br />&#160;while(rs.next()){<br />&#160;&#160;cellobj.put("id",rs.getInt(1));<br />&#160;&#160;cell.add(rs.getInt(1));<br />&#160;&#160;cell.add(rs.getString(2));<br />&#160;&#160;cell.add(rs.getString(3));<br />&#160;&#160;cellobj.put("cell",cell);<br />&#160;&#160;cell.clear();<br />&#160;&#160;cellarray.add(cellobj);<br />&#160;&#160;i++;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160; PrintWriter out = response.getWriter();<br />&#160; responcedata.put("rows",cellarray);<br />&#160;&#160;&#160; <br />&#160; return responcedata;</em></p>
<p><em>}</em></p>
<p><em>&#160;</em></p>
<p>The struts-config.xml action forward mapping points to an empty.jsp that has no specific code.</p>
</p>
<p>The jsp file formulates the jqgrid as shown below:</p>
</p>
<p><em>$(document).ready(function(){<br />$("#load_callback1").click(function(){<br />jQuery("#list10").jqGrid({<br />&#160;</em><a href="/blog/&#39;/PeakAlpha/mutualfund.do?method=getMFTransDetails1&#39;" target="_blank"><em>url:&#39;/TestJSON/testAction.do?method=getJSONData&#39;</em></a><em>,<br />&#160;datatype: "json",<br />&#160;&#160; &#160;colNames:[&#39;Invoice Number&#39;,&#39;Invoice Date&#39;,&#39;Invoice Name&#39;],<br />&#160;&#160; &#160;colModel:[<br />&#160;&#160; &#160;&#160;{name:&#39;id&#39;,index:&#39;id&#39;, id:&#39;id&#39;,width:90},<br />&#160;&#160; &#160;&#160;{name:&#39;invdate&#39;,index:&#39;invdate&#39;, width:120},<br />&#160;&#160; &#160;&#160;{name:&#39;invname&#39;,index:&#39;invname&#39;, width:200}<br />&#160;&#160; &#160;],<br />&#160;&#160; &#160;rowNum:10,<br />&#160;&#160; &#160;autowidth: true,<br />&#160;&#160; &#160;rowList:[10,20,30],<br />&#160;&#160; &#160;pager: jQuery(&#39;#pager1&#39;),<br />&#160;&#160; &#160;sortname: &#39;invname&#39;,<br />&#160;&#160;&#160; sortorder: "desc",<br />&#160;&#160;&#160; caption:"JSON Example"<br />}).navGrid(&#39;#pager1&#39;,{edit:false,add:false,del:false});&#160;<br />});<br />});</em></p>
</p>
<p>The grid comes up with no data. A similar example works well with the doGet method of a servlet.</p>
</p>
<p>Questions:</p>
<p>1) How do we obtain the json object returned from a struts action method?</p>
<p>2) Is there any process to be done in the empty.jsp file to handle the response object and obtain the json data?</p>
</p>
<p>Not sure if I posted the question under the right topic. Awaiting for a clarification at the earliest. Thank you.</p>
</p>
<p>Regards,</p>
<p>Aarati</p>
<p><em>&#160;</em></p>
</p>
<p>Regards,</p>
<p>Aarati</p>
]]></description>
        	        	<pubDate>Wed, 05 Jan 2011 19:01:38 +0200</pubDate>
        </item>
        <item>
        	<title>tony on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14558</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14558</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Sorry it was my mistake. Of course it is a object.</p>
<p>If you know some property of this object you can</p>
</p>
<p>alert(request.myobjectname);</p>
</p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Fri, 05 Feb 2010 11:24:33 +0200</pubDate>
        </item>
        <item>
        	<title>mikesmith on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14486</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14486</guid>
        	        	<description><![CDATA[<p>I tried that but the alert was: [object Object] 🙁</p></p>
]]></description>
        	        	<pubDate>Tue, 02 Feb 2010 01:49:48 +0200</pubDate>
        </item>
        <item>
        	<title>tony on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14433</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14433</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>You shoud use request directly, and not request.responsText</p>
<p>try alert(request);</p>
<p>Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Mon, 01 Feb 2010 08:51:31 +0200</pubDate>
        </item>
        <item>
        	<title>mikesmith on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14395</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14395</guid>
        	        	<description><![CDATA[<p>I tried doing this and when I alert(request.responseText) I get undefined. and also request.status gives me undefined.</p>
</p>
<p>I am new to all this so your help is appreciated.</p>
]]></description>
        	        	<pubDate>Fri, 29 Jan 2010 12:41:20 +0200</pubDate>
        </item>
        <item>
        	<title>tony on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14358</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14358</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Use loadComplete - the parameter passed to it is the request</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit9229' value='Select Code' data-codeid='sfcode9229' /></p>
<div class='sfcode' id='sfcode9229'>
<p>loadComplete : function(request)</p>
<p>{</p>
<p>// do somthing here with the request</p>
<p>}</p>
</div>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Thu, 28 Jan 2010 17:30:13 +0200</pubDate>
        </item>
        <item>
        	<title>mikesmith on How do I access JSON string in jsp?</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14293</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/how-do-i-access-json-string-in-jsp#p14293</guid>
        	        	<description><![CDATA[<p>Hi. Im implenting struts &#38;jquery.</p>
<p>my action will return a JSON string to my jsp. What do I need to do to access the JSON string after the ajax call has already been made?</p>
</p>
<p>I am implementing the grid. I have added serveral key/value pairs in my JSON string that will NOT be in the grid.</p>
<p>And I want to use these extra values to implement some logic after the ajax callis complete.</p>
</p>
<p>I have put onCompleteTopics="complete" in my grid. This calls:</p>
<p>&#160;&#160;&#160; $.subscribe(&#39;complete&#39;, function(data){ <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; var res = jQuery.getJSON();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; alert(rest);<br />&#160;&#160;&#160; });</p>
</p>
<p>Howevers, res is not my JSON string that is returned to the jgrid by my action.</p>
</p>
<p>Any one with ideas how I can access the json string that org.apache.struts2.json.JSONUtil serlializes and sends to the jsp?</p>
</p>
<p>merci</p></p>
]]></description>
        	        	<pubDate>Tue, 26 Jan 2010 19:06:59 +0200</pubDate>
        </item>
</channel>
</rss>