Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am making a YUI AJAX call from my JSP as

   var oConnect = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); 

The URL specified is

 var sUrl = "http://localhost:8080/Test/TreeViewData.do";

The call is going to the TreeViewAction.java , based on entries in struts-config.xml and the following is getting executed-

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 
System.out.println("Inside Action"); 
JSONObject company = new JSONObject(); 
company.put("name","Software Inc."); 
JSONArray employees = new JSONArray();

JSONObject employee1 = new JSONObject();     
JSONObject employee2 = new JSONObject();     
employee2.put("name"," Joe");      
response.setHeader("Cache-Control", "no-cache");       

//Even tried this     //company.write(response.getWriter());      

return (mapping.findForward(Constants.SUCCESS)); }

On succes it returns to the main JSP, but the response received is not in JSON format and not getting Parsed using -

try { 
var theResponse = YAHOO.lang.JSON.parse(oResponse.responseText); 
} catch (e) 
{ alert(e.message); 

It gives JASON.parse exception as message.

When I do alert(oResponse.getAllResponseHeaders),I get-

Content-Type:text/html;charset:UTF-8  T
ransfer-Encoding: chunked  
Date:Fri 10 dec  

and on alert(oResponse.responseText); I get

   <link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />    <link rel="stylesheet" type="text/css" href="../../build/treeview/assets/skins/sam/treeview.css" />     <script type="text/javascript" src="jscripts/yuiloader/yuiloader.js"></script>     <script type="text/javascript" src="jscripts/yahoo-dom-event/yahoo-dom-event.js"></script>        <script type="text/javascript" src="jscripts/treeview/treeview-min.js"></script> ....and so on....

Could someone please help get his Jason data in JSP, I am trying to implement a YUI treeview which will take the data from javaaction class(not PHP) and create a dynamic tree.

share|improve this question
Please format your code so it's at least a little bit readable. –  Dennis Williamson Dec 11 '10 at 0:44
Apologies for the same, have formatted now. –  user63264 Dec 11 '10 at 10:20
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.