PDA

View Full Version : values are not loading ito my json store



kirankumar1231
17 Mar 2011, 8:40 PM
hello experts
i have been struggling to find a solution on this thing as i am new to this extjs and stuff

my database values are not getting loaded to my json store
i dont know what could be the problem
this is the server response

{"employee":[{"empid":123,"empname":"kiran kumar"},{"empid":1231,"empname":"kiran"}]}

following is my entire code

this is my home.jsp



<%@

page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>


<!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>


</head>


<body>


<form action="get.html">


<input type="submit"></input>


</form>


</body>



</html>


this is my Json.java



import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import sun.net.www.http.HttpClient;
import net.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Json extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
ArrayList<Employee> emp=new ArrayList<Employee>();
Myservice serve=new Myservice();
emp=serve.getemployeesservice();
Iterator<Employee> empitr=emp.iterator();
JSONArray json=new JSONArray();
JSONObject JSONobj=new JSONObject();
while(empitr.hasNext()){
JSONObject jobj=new JSONObject();
Employee empl=new Employee();
empl=empitr.next();
jobj.put("empid",empl.getEmpid());
jobj.put("empname",empl.getEmpname());
json.add(jobj);
}
JSONobj.put("employee",json.toString());
return mapping.findForward("success");
}


}




this is my getvalues.jsp




<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>


<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c">

<!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" href="css/ext-all.css">


<script type="text/javascript" src="js/ext-base.js"></script>


<script type="text/javascript" src="js/ext-all.js"></script>

<script type="text/javascript">


Ext.onReady(function() {


Ext.QuickTips.init();

var store=new Ext.data.JsonStore({
url: 'http://localhost:8080/JsonExample/get.html',
root: 'employee',
idProperty: 'empid',
fields: [{name: 'empid', type: 'int'}, {name: 'empname'}],
autoLoad: true
});
store.load();
var colModel = new Ext.grid.ColumnModel([
{header: "empid", width: 120, sortable: true, dataIndex: 'empid'},
{header: "empname", width: 90, sortable: true, dataIndex: 'empname'}
]);


var grid = new Ext.grid.GridPanel({ height:200, width:600, ds:store, cm: colModel});


grid.render(document.body);

grid.getSelectionModel().selectFirstRow();


});


</script>

</head>


<body>


</body>



</html>


this is my struts-config file




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC


"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"


"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
<action-mappings>
<action path="/get" type="Json">
<forward name="success" path="/getvalues.jsp"></forward>
</action>
</action-mappings>
</struts-config>






this is my web.xml file




<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


<display-name>JsonExample</display-name>


<welcome-file-list>

<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>








values are not getting loaded to my extjs grid
i am getting an empty grid