我正在尝试将表单数据从jqgrid发送到spring mvc控制器但是我收到了错误
HTTP Status 404-The requested resource is not available.
。
以下是我的代码。
1)OverviewController.java
@Controller
@RequestMapping(value="Overview")
public class OverviewController
{
@Autowired
OverviewService service;
@RequestMapping(value="Order.spring",method=RequestMethod.GET)
public ModelAndView getOrderView(ModelMap map,HttpSession session)
{
ModelAndView modelAndView=new ModelAndView("ViewOrders");
modelAndView.addObject("ViewOrders", new OrderOverviewForm());
return modelAndView;
}
@RequestMapping(value="Order.spring",method=RequestMethod.POST,produces="application/json")
public @ResponseBody OrderOverviewResponse getOrderOverview(@RequestParam("AccId") Integer AccId
,@RequestParam("FromDate")Date FromDate
,@RequestParam("ToDate")Date ToDate
,@RequestParam("TransactionType") String TransactionType
,@RequestParam("_search") Boolean search
,@RequestParam(value="page", required=false) Integer page
,@RequestParam(value="rows", required=false) Integer rows
,@RequestParam(value="sidx", required=false) String sidx
,@RequestParam(value="sord", required=false) String sord)
{
// System.out.println(form);
OrderOverviewForm form=new OrderOverviewForm(FromDate, ToDate, AccId, TransactionType);
System.out.println("In overview POST");
List<OrderOverviewData> datas=(List<OrderOverviewData>)service.getOrderOverview(form, 1);
for (Iterator iterator = datas.iterator(); iterator.hasNext();) {
OrderOverviewData orderOverviewData = (OrderOverviewData) iterator.next();
System.out.println(orderOverviewData);
}
OrderOverviewResponse response=new OrderOverviewResponse();
response.setPage("1");
response.setTotal("5");
response.setRows(datas);
response.setRecords(String.valueOf(datas.size()));
return response;
}
}
2) ViewOrders.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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">
<script type="text/javascript"
src="<c:url value="/resources/js/jquery-1.11.1.min.js"></c:url>"></script>
<script type="text/javascript"
src="<c:url value="/resources/js/jquery.jqGrid.min.js"></c:url>"></script>
<script type="text/javascript"
src="<c:url value="/resources/js/jquery-ui.min.js"></c:url>"></script>
<link type="text/css" rel="stylesheet"
href="<c:url value="/resources/css/jquery-ui.min.css"></c:url>" />
<link type="text/css" rel="stylesheet"
href="<c:url value="/resources/css/ui.jqgrid.css"></c:url>" />
<script type="text/javascript">
$(function() {
$("#target")
.submit(
function(event) {
alert("H");
var data={};
data["AccId"]= $('#AccId').val();
data["FromDate"]= $('#FromDate').val();
data["ToDate"]= $('#ToDate').val();
data["TransactionType"]= $('#TransactionType').val();
$("#grid")
.jqGrid(
{
url : '/Online Fund Trading/Overview/Order.spring',
datatype : 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
mtype : 'POST',
colNames : [ 'Customer Id',
'Account Id',
'Order Id',
'Order Date',
'Order Amount',
'Order Units',
'Order Type', 'Fund Id' ],
colModel : [ {
name : 'CusId',
index : 'CusId',
width : 15,
editable : false,
editoptions : {
readonly : true,
size : 10
},
hidden : true
}, {
name : 'AccId',
index : 'AccId',
width : 15,
editable : true,
editrules : {
required : true
},
editoptions : {
size : 10
}
}, {
name : 'OrdId',
index : 'OrdId',
width : 15,
editable : false,
editrules : {
required : true
},
editoptions : {
size : 10
}
}, {
name : 'OrdDate',
index : 'OrdDate',
width : 15,
editable : false,
editrules : {
required : true
},
editoptions : {
size : 10
}
}, {
name : 'OrdAmount',
index : 'OrdAmount',
width : 15,
editable : false,
editrules : {
required : true
},
editoptions : {
size : 10
}
}, {
name : 'OrdUnits',
index : 'OrdUnits',
width : 15,
editable : false,
editrules : {
required : true
},
editoptions : {
size : 10
}
}, {
name : 'OrdType',
index : 'OrdType',
width : 15,
editable : false,
editrules : {
required : true
},
editoptions : {
size : 10
}
}, {
name : 'FundId',
index : 'FundId',
width : 15,
editable : false,
editrules : {
required : true
},
editoptions : {
size : 10
}
}
],
postData : {
AccId : function() {
return $('#AccId')
.val();
},
FromDate : function() {
return $('#FromDate')
.val();
},
ToDate : function() {
return $('#FromDate')
.val();
},
TransactionType : function() {
return $('#FromDate')
.val();
}
},
rowNum : 20,
rowList : [ 20, 40, 60 ],
height : 200,
autowidth : true,
rownumbers : true,
pager : '#pager',
sortname : 'CusId',
viewrecords : true,
sortorder : "asc",
caption : "Orders Overview",
emptyrecords : "Empty records",
loadonce : false,
loadComplete : function() {
},
jsonReader : {
root : "rows",
page : "page",
total : "total",
records : "records",
repeatitems : false,
cell : "cell",
id : "id"
}
});
event.preventDefault();
});
});
</script>
</head>
<body>
<form id="target" enctype="application/json">
<table>
<tr>
<td>Enter AccId</td>
<td><input type="text" id="AccId" /></td>
</tr>
<tr>
<td>From Date</td>
<td><input type="text" id="FromDate" /></td>
<td>To Date</td>
<td><input type="text" id="ToDate" /></td>
</tr>
<tr>
<td>Enter Transaction Type</td>
<td><input type="text" id="TransactionType" /></td>
</tr>
<tr>
<td colspan="4"><input type="submit" id="submit"
value="Get Orders"></td>
</tr>
</table>
</form>
<div id="jqgrid">
<table id="grid"></table>
<div id="pager"></div>
</div>
</body>
</html>
<br />
我已经在mozilla中跟踪了请求和响应的内容。
Source
AccId=100&FromDate=&ToDate=&TransactionType=&_search=false&nd=1414507225627&rows=20&page=1&sidx=CusId&sord=asc
以及请求和响应内容,
Response Headersview source
Server Apache-Coyote/1.1
Content-Type text/html;charset=utf-8
Content-Length 1041
Date Tue, 28 Oct 2014 14:40:25 GMT
Request Headersview source
Host localhost:8080
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/json; charset=utf-8
X-Requested-With XMLHttpRequest
Referer http://localhost:8080/Online_Fund_Trading/Overview/Order.spring
Content-Length 110
我也添加了杰克逊罐子,但仍然没有得到我做错了什么。 请帮我解决这个问题。 感谢。