Spring mvc with jqgrid simplified
Hello Friends.hope you all are fine.today i am going to demonstrate jqgrid functionality of jquery & how can we intract with database using spring mvc .jqgrid represents data in tabular format.i am using json data for forwarding request & response to the client..
well i have included jquery.jqGrid.min.js,jquery.min.js,jquery-ui.custom.js java script files into the classpath.
i am posting my code as given below :
Entity Class:
package org.demo.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="student")
public class Student
{
@Id
@Column
private int studentid;
@Column
private String name;
@Column
private String college;
public Student() { }
public Student(int id, String name,String college)
{
this.studentid=id;
this.name=name;
this.college=college;
}
public int getStudentid() {
return studentid;
}
public void setStudentid(int studentid) {
this.studentid = studentid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
}
Controller :
package org.demo.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.demo.dao.StudentDAO;
import org.demo.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.orb.Utills.JsonMapper;
@Controller
public class StudentController {
@RequestMapping(value = "/Data", method = RequestMethod.GET)
public @ResponseBody
void getStudent(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// to get applicationcontext associated with ioc container -use to get
// specific beans
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(request.getServletContext());
StudentDAO dao = (StudentDAO) context.getBean("StudentDAO");
List<Student> list = dao.saveAllStudents();
Map<String, Object> personMap = new LinkedHashMap<String, Object>();
List<Map<String, Object>> personList = new ArrayList<Map<String, Object>>();
Map<String, Object> personSubMap = null;
List<String> cell = null;
int i = 0;
for (Student p : list) {
i++;
personSubMap = new LinkedHashMap<String, Object>();
personSubMap.put("id", p.getStudentid());
cell = new ArrayList<String>();
cell.add(p.getStudentid() + "");
cell.add(p.getName());
cell.add(p.getCollege());
personSubMap.put("cell", cell);
personList.add(personSubMap);
}
personMap.put("rows", personList);
personMap.put("records", i);
JsonMapper json = (JsonMapper) context.getBean("JsonMapper");
json.WritecInJson(response, personMap);
/* return personMap; */
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public @ResponseBody
void edit(HttpServletRequest request, HttpServletResponse res) {
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(request.getServletContext());
System.out.println("inside");
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String college = request.getParameter("college");
String operation = request.getParameter("oper");
StudentDAO dao = context.getBean("StudentDAO", StudentDAO.class);
Student s = new Student(id, name, college);
if (operation.equals("add")) {
dao.insert(s);
System.out.println(name);
Map<String, Student> studentMap = new HashMap<String, Student>();
studentMap.put("data", new Student(id, name, college));
JsonMapper json = (JsonMapper) context.getBean("JsonMapper");
json.WritecInJson(res, studentMap);
}
if (operation.equals("edit")) {
System.out.println(name);
dao.edit(id, name, college);
Map<String, Student> studentMap = new HashMap<String, Student>();
studentMap.put("data", new Student(id, name, college));
JsonMapper json = (JsonMapper) context.getBean("JsonMapper");
json.WritecInJson(res, studentMap);
}
if (operation.equals("del")) {
dao.delete(id);
}
}
}
DAO:
package org.demo.dao;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.demo.model.Student;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateTemplate;
public class StudentDAO
{
private HibernateTemplate template;
public StudentDAO(HibernateTemplate template) throws Exception
{
this.template=template;
}
public List<Student> saveAllStudents() throws Exception
{
List<org.demo.model.Student> StudentList=template.find("FROM Student");
return StudentList;
/* System.out.println("Done");*/
}
public void insert(Student s)
{
template.save(s);
}
public void edit(int id,String name,String college)
{
Query query =template.getSessionFactory().openSession().createSQLQuery("update Student set name=? ,college=? where studentid=? ");
query.setString(0,name);
query.setString(1,college);
query.setInteger(2,id);
int success=query.executeUpdate();
System.out.println("updated SUCCESSFULLY!!!" +success);
}
public void delete(int id)
{
Query query =template.getSessionFactory().openSession().createSQLQuery("delete from Student where studentid=? ");
query.setInteger(0,id);
int success=query.executeUpdate();
System.out.println("Deleted SUCCESSFULLY!!!");
}
}
Mapper class: user defined json coverter
package com.orb.Utills;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
public class JsonMapper {
public void WritecInJson(HttpServletResponse res, Object object) {
MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter();
MediaType jsonMimeType = MediaType.APPLICATION_JSON;
if (jsonConverter.canWrite(object.getClass(), jsonMimeType)) {
try {
jsonConverter.write(object, jsonMimeType,
new ServletServerHttpResponse(res));
} catch (IOException e) {
e.printStackTrace();
} catch (HttpMessageNotWritableException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("reached in else");
}
}
}
JqgridDemo.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>
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="script/jquery-ui.custom.min.js"></script>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.10.0.custom.css"/>
<link type="text/css" rel="stylesheet" href="css/ui.jqgrid.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JQGrid Demo</title>
<script type="text/javascript">
jQuery().ready(function (){
/*
$("#dialog").dialog({
autoOpen : false,
width : 650,
resizable:false,
modal : true,
close : function(ev, ui) {
alert("closed");
}
});
$("#btn").click(function(){
$("#dialog").dialog('open');
}); */
jQuery("#list1").jqGrid({
url:'Data.html',
editurl:'edit.html',
datatype: "json",
colNames:['ID','NAME','COLLEGE'],
colModel:[
{name:'id',index:'id', width:80,align:"right",editable:true,editoptions:{rows:"2",cols:"20"}},
{name:'name',index:'name', width:80,align:"right",editable:true,editoptions:{rows:"2",cols:"20"}},
{name:'college',index:'college', width:150, sortable:false,editable:true, editoptions:{rows:"2",cols:"20"}} ],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager1'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"CRUD" }).navGrid('#pager1',{ 'cellEdit': true,add : true,edit :true,save :true,addtext: 'Add',edittext:'edit',searchtext:'Search',deletetext:'delete',savetext:'Save',canceltext: 'Cancel',editable:true},{});
});
$.jgrid.edit = {
addCaption: "Add Student",
editCaption: "Edit Student",
bSubmit: "Submit",
bCancel: "Cancel",
bClose: "Close",
bYes : "Yes",
bNo : "No",
bExit : "Cancel",
closeAfterAdd:true,
closeAfterEdit:true,
reloadAfterSubmit:true,
errorTextFormat: function (response) {
if (response.status != 200) {
return "Error encountered while processing. Please check the accuracy of data entered.";
}
},
afterSubmit : function(response,postdata) {
return(true,"ok");
}
};
$("#dedata").click(function(){ var gr = jQuery("#delgrid").jqGrid('getGridParam','selrow'); if( gr != null ) jQuery("#list").jqGrid('delGridRow',gr,{reloadAfterSubmit:false}); else alert("Please Select Row to delete!"); });
$.jgrid.del = {
caption: "Delete Student",
msg: "Delete selected student?",
bSubmit: "Delete",
bCancel: "Cancel",
reloadAfterSubmit:true,
closeOnEscape:true,
onclickSubmit : function(eparams) {
var rowData = $("#list").jqGrid('getRowData', 1);
var retarr = {'id':rowData['id']};
return retarr;
}
};
jQuery("#list1").jqGrid('editRow',1,
{
keys : true,
oneditfunc: function() {
alert ("edited");
}
});
jQuery("#list1").jqGrid('navGrid', '#pager1', {edit : false,add : false,del : false,search : false});
jQuery("#list1").jqGrid('inlineNav',"#pager1",{add : true,edit :false,save :true,addtext: 'Add',savetext:'Save',canceltext: 'Cancel'});
</script>
</head>
<body>
<div id="dialog">
<table id="list1"></table> <div id="pager1"></div>
</div>
<button id="btn" value="show"></button>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TestJquery</display-name>
<welcome-file-list>
<welcome-file>jqgridDemo.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/context-conf.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
context file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/demo" />
<property name="username" value="root" />
<property name="password" value="admin!@#"/>
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses" value="org.demo.model.Student">
<!-- <props>
<prop key="classes" >org.demo.model.Student</prop>
</props>
<list>
<value>org.demo.model.Student</value>
</list> -->
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<constructor-arg ref="mySessionFactory" />
</bean>
<bean id="JsonMapper" class="com.orb.Utills.JsonMapper"></bean>
<bean id="StudentDAO" class="org.demo.dao.StudentDAO">
<constructor-arg ref="hibernateTemplate" />
</bean>
</beans>
the output will look like as given below :
hope you will get my point .thanks for reading this post
for any query ping me on pathak.nisarg@yahoo.com
Regards
Hello Friends.hope you all are fine.today i am going to demonstrate jqgrid functionality of jquery & how can we intract with database using spring mvc .jqgrid represents data in tabular format.i am using json data for forwarding request & response to the client..
well i have included jquery.jqGrid.min.js,jquery.min.js,jquery-ui.custom.js java script files into the classpath.
i am posting my code as given below :
Entity Class:
package org.demo.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="student")
public class Student
{
@Id
@Column
private int studentid;
@Column
private String name;
@Column
private String college;
public Student() { }
public Student(int id, String name,String college)
{
this.studentid=id;
this.name=name;
this.college=college;
}
public int getStudentid() {
return studentid;
}
public void setStudentid(int studentid) {
this.studentid = studentid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
}
Controller :
package org.demo.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.demo.dao.StudentDAO;
import org.demo.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.orb.Utills.JsonMapper;
@Controller
public class StudentController {
@RequestMapping(value = "/Data", method = RequestMethod.GET)
public @ResponseBody
void getStudent(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// to get applicationcontext associated with ioc container -use to get
// specific beans
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(request.getServletContext());
StudentDAO dao = (StudentDAO) context.getBean("StudentDAO");
List<Student> list = dao.saveAllStudents();
Map<String, Object> personMap = new LinkedHashMap<String, Object>();
List<Map<String, Object>> personList = new ArrayList<Map<String, Object>>();
Map<String, Object> personSubMap = null;
List<String> cell = null;
int i = 0;
for (Student p : list) {
i++;
personSubMap = new LinkedHashMap<String, Object>();
personSubMap.put("id", p.getStudentid());
cell = new ArrayList<String>();
cell.add(p.getStudentid() + "");
cell.add(p.getName());
cell.add(p.getCollege());
personSubMap.put("cell", cell);
personList.add(personSubMap);
}
personMap.put("rows", personList);
personMap.put("records", i);
JsonMapper json = (JsonMapper) context.getBean("JsonMapper");
json.WritecInJson(response, personMap);
/* return personMap; */
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public @ResponseBody
void edit(HttpServletRequest request, HttpServletResponse res) {
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(request.getServletContext());
System.out.println("inside");
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String college = request.getParameter("college");
String operation = request.getParameter("oper");
StudentDAO dao = context.getBean("StudentDAO", StudentDAO.class);
Student s = new Student(id, name, college);
if (operation.equals("add")) {
dao.insert(s);
System.out.println(name);
Map<String, Student> studentMap = new HashMap<String, Student>();
studentMap.put("data", new Student(id, name, college));
JsonMapper json = (JsonMapper) context.getBean("JsonMapper");
json.WritecInJson(res, studentMap);
}
if (operation.equals("edit")) {
System.out.println(name);
dao.edit(id, name, college);
Map<String, Student> studentMap = new HashMap<String, Student>();
studentMap.put("data", new Student(id, name, college));
JsonMapper json = (JsonMapper) context.getBean("JsonMapper");
json.WritecInJson(res, studentMap);
}
if (operation.equals("del")) {
dao.delete(id);
}
}
}
DAO:
package org.demo.dao;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.demo.model.Student;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateTemplate;
public class StudentDAO
{
private HibernateTemplate template;
public StudentDAO(HibernateTemplate template) throws Exception
{
this.template=template;
}
public List<Student> saveAllStudents() throws Exception
{
List<org.demo.model.Student> StudentList=template.find("FROM Student");
return StudentList;
/* System.out.println("Done");*/
}
public void insert(Student s)
{
template.save(s);
}
public void edit(int id,String name,String college)
{
Query query =template.getSessionFactory().openSession().createSQLQuery("update Student set name=? ,college=? where studentid=? ");
query.setString(0,name);
query.setString(1,college);
query.setInteger(2,id);
int success=query.executeUpdate();
System.out.println("updated SUCCESSFULLY!!!" +success);
}
public void delete(int id)
{
Query query =template.getSessionFactory().openSession().createSQLQuery("delete from Student where studentid=? ");
query.setInteger(0,id);
int success=query.executeUpdate();
System.out.println("Deleted SUCCESSFULLY!!!");
}
}
Mapper class: user defined json coverter
package com.orb.Utills;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
public class JsonMapper {
public void WritecInJson(HttpServletResponse res, Object object) {
MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter();
MediaType jsonMimeType = MediaType.APPLICATION_JSON;
if (jsonConverter.canWrite(object.getClass(), jsonMimeType)) {
try {
jsonConverter.write(object, jsonMimeType,
new ServletServerHttpResponse(res));
} catch (IOException e) {
e.printStackTrace();
} catch (HttpMessageNotWritableException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("reached in else");
}
}
}
JqgridDemo.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>
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="script/jquery-ui.custom.min.js"></script>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.10.0.custom.css"/>
<link type="text/css" rel="stylesheet" href="css/ui.jqgrid.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JQGrid Demo</title>
<script type="text/javascript">
jQuery().ready(function (){
/*
$("#dialog").dialog({
autoOpen : false,
width : 650,
resizable:false,
modal : true,
close : function(ev, ui) {
alert("closed");
}
});
$("#btn").click(function(){
$("#dialog").dialog('open');
}); */
jQuery("#list1").jqGrid({
url:'Data.html',
editurl:'edit.html',
datatype: "json",
colNames:['ID','NAME','COLLEGE'],
colModel:[
{name:'id',index:'id', width:80,align:"right",editable:true,editoptions:{rows:"2",cols:"20"}},
{name:'name',index:'name', width:80,align:"right",editable:true,editoptions:{rows:"2",cols:"20"}},
{name:'college',index:'college', width:150, sortable:false,editable:true, editoptions:{rows:"2",cols:"20"}} ],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager1'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"CRUD" }).navGrid('#pager1',{ 'cellEdit': true,add : true,edit :true,save :true,addtext: 'Add',edittext:'edit',searchtext:'Search',deletetext:'delete',savetext:'Save',canceltext: 'Cancel',editable:true},{});
});
$.jgrid.edit = {
addCaption: "Add Student",
editCaption: "Edit Student",
bSubmit: "Submit",
bCancel: "Cancel",
bClose: "Close",
bYes : "Yes",
bNo : "No",
bExit : "Cancel",
closeAfterAdd:true,
closeAfterEdit:true,
reloadAfterSubmit:true,
errorTextFormat: function (response) {
if (response.status != 200) {
return "Error encountered while processing. Please check the accuracy of data entered.";
}
},
afterSubmit : function(response,postdata) {
return(true,"ok");
}
};
$("#dedata").click(function(){ var gr = jQuery("#delgrid").jqGrid('getGridParam','selrow'); if( gr != null ) jQuery("#list").jqGrid('delGridRow',gr,{reloadAfterSubmit:false}); else alert("Please Select Row to delete!"); });
$.jgrid.del = {
caption: "Delete Student",
msg: "Delete selected student?",
bSubmit: "Delete",
bCancel: "Cancel",
reloadAfterSubmit:true,
closeOnEscape:true,
onclickSubmit : function(eparams) {
var rowData = $("#list").jqGrid('getRowData', 1);
var retarr = {'id':rowData['id']};
return retarr;
}
};
jQuery("#list1").jqGrid('editRow',1,
{
keys : true,
oneditfunc: function() {
alert ("edited");
}
});
jQuery("#list1").jqGrid('navGrid', '#pager1', {edit : false,add : false,del : false,search : false});
jQuery("#list1").jqGrid('inlineNav',"#pager1",{add : true,edit :false,save :true,addtext: 'Add',savetext:'Save',canceltext: 'Cancel'});
</script>
</head>
<body>
<div id="dialog">
<table id="list1"></table> <div id="pager1"></div>
</div>
<button id="btn" value="show"></button>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TestJquery</display-name>
<welcome-file-list>
<welcome-file>jqgridDemo.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/context-conf.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
context file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/demo" />
<property name="username" value="root" />
<property name="password" value="admin!@#"/>
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses" value="org.demo.model.Student">
<!-- <props>
<prop key="classes" >org.demo.model.Student</prop>
</props>
<list>
<value>org.demo.model.Student</value>
</list> -->
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<constructor-arg ref="mySessionFactory" />
</bean>
<bean id="JsonMapper" class="com.orb.Utills.JsonMapper"></bean>
<bean id="StudentDAO" class="org.demo.dao.StudentDAO">
<constructor-arg ref="hibernateTemplate" />
</bean>
</beans>
the output will look like as given below :
hope you will get my point .thanks for reading this post
for any query ping me on pathak.nisarg@yahoo.com
Regards