我正在尝试在我的项目中实现jqgrid。但是,我在运行应用程序时收到以下异常。无法解决错误。一些帮助表示赞赏。我的项目是Spring MVC + Hibernate + JQGrid。
type Exception report
message Request processing failed; nested exception is java.lang.NumberFormatException: null
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NumberFormatException: null
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
root cause
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:542)
java.lang.Integer.parseInt(Integer.java:615)
com.nej.controller.BranchMstController.getAll(BranchMstController.java:37)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
我的Controller文件与此错误来自branchmstcontroller.java
的位置/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.nej.controller;
import com.nej.branchmst.model.BranchMst;
import com.nej.branchmst.service.BranchMstService;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
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.servlet.ModelAndView;
/**
*
* @author Tushar
*/
@Controller
@RequestMapping(value={"/admin/branchmstmgmt"})
public class BranchMstController {
@Autowired
private BranchMstService branchmstService;
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody BranchmstResponse getAll(HttpServletRequest request){
int rows = 0;
rows = Integer.parseInt(request.getParameter("rows"));
int page = Integer.parseInt(request.getParameter("page"));
String sidx = request.getParameter("sidx");
String sord = request.getParameter("sord");
List<BranchMst> list = null;
list = branchmstService.getBranchMsts(rows, page, sidx, sord);
BranchmstResponse response = new BranchmstResponse();
response.setRows(list);
int count = branchmstService.getNoOfRecords();
int total = count%rows == 0 ? (int)Math.ceil(count/rows) : (int)Math.ceil(count/rows)+1;
response.setTotal(total);
response.setRecords(count);
response.setPage(page);
return response;
}
@RequestMapping(value="/edit")
public ModelAndView doEdit(HttpServletRequest request){
Byte brcmpcode = 0;
Integer brcode = 0;
String brname = null, bradd1 = null, bradd2 = null, brcity = null, brpin = null;
String bremail = null, brcontactperson = null, oper = null;
Enumeration<String> paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()){
String s = paramNames.nextElement();
if("brcode".equalsIgnoreCase(s)){
brcode = Integer.parseInt(request.getParameter("brcode"));
}else if("brcmpcode".equalsIgnoreCase(s)){
brcmpcode = Byte.parseByte(request.getParameter("brcmpcode"));
}else if("brname".equalsIgnoreCase(s)){
brname = request.getParameter("brname");
}else if("bradd1".equalsIgnoreCase(s)){
bradd1 = request.getParameter("bradd1");
}else if("bradd2".equalsIgnoreCase(s)){
bradd2 = request.getParameter("bradd2");
}else if("brcity".equalsIgnoreCase(s)){
brcity = request.getParameter("brcity");
}else if("brpin".equalsIgnoreCase(s)){
brpin = request.getParameter("brpin");
}else if("bremail".equalsIgnoreCase(s)){
bremail = request.getParameter("bremail");
}else if("brcontactperson".equalsIgnoreCase(s)){
brcontactperson = request.getParameter("brcontactperson");
}else if("oper".equalsIgnoreCase(s)){
oper = request.getParameter("oper");
}
}
Map<String, String> model = new HashMap<String, String>();
if("edit".equalsIgnoreCase(oper)){
BranchMst branchmst = new BranchMst();
branchmst.setBrCmpcode(brcmpcode);
branchmst.setBrcode(brcode);
branchmst.setBrname(brname);
branchmst.setBradd1(bradd1);
branchmst.setBradd2(bradd2);
branchmst.setBrcity(brcity);
branchmst.setBrpin(brpin);
branchmst.setBremail(bremail);
branchmst.setBrcontactperson(brcontactperson);
branchmstService.updateBranchMst(branchmst);
}else if("add".equalsIgnoreCase(oper)){
BranchMst branchmst = branchmstService.getBranchMst(brcode);
if(branchmst == null){
branchmst = new BranchMst();
branchmst.setBrCmpcode(brcmpcode);
branchmst.setBrcode(brcode);
branchmst.setBrname(brname);
branchmst.setBradd1(bradd1);
branchmst.setBradd2(bradd2);
branchmst.setBrcity(brcity);
branchmst.setBrpin(brpin);
branchmst.setBremail(bremail);
branchmst.setBrcontactperson(brcontactperson);
branchmstService.saveBranchMst(branchmst);
}else{
throw new RuntimeException();
}
}else if("del".equalsIgnoreCase(oper)){
branchmstService.deleteBranchMst(brcode);
}
return new ModelAndView("branchmstmgmt",model);
}
}
相关的JSP文件如下:branchmstmgmt.jsp
<%--
Document : branchmstmgmt
Created on : Sep 13, 2014, 3:01:07 PM
--%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page session="true"%>
<tiles:insertDefinition name="defaultTemplate">
<tiles:putAttribute name="body">
<%@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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/styles/pure-0.4.2.css"/>
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/styles/jquery-ui.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="${pageContext.request.contextPath}/resources/styles/jquery-ui.css" />
<link rel="stylesheet" type="text/css" media="screen" href="${pageContext.request.contextPath}/resources/styles/ui.jqgrid.css" />
<script src="${pageContext.request.contextPath}/resources/script/jquery-latest.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/resources/script/grid.locale-en.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/resources/script/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/resources/script/js-for-branchmst.js" type="text/javascript"></script>
<body>
<table id="list" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</body>
</html>
</tiles:putAttribute>
</tiles:insertDefinition>
实现JQGrid的.js文件如下所示:js-for-branchmst.js
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var row_selected;
$(document).ready(function(){
$("#list").jqGrid({
datatype: 'json',
mtype: 'GET',
height: 'auto',
url:'/admin/branchmstmgmt',
editurl:'/admin/branchmstmgmt/edit',
colNames:['Company','Branch','Branch Name','Address-1','Address-2','City','Pin','E-Mail','Contact Person'],
colModel:[
{name:'brcmpcode',index:'brcmpcode', width:50, editable:true, editrules:{required:true,number:true}, editoptions:{size:10}, formoptions:{elmprefix:'*'}},
{name:'brcode',index:'brcode', width:50, editable:true, editrules:{required:true,number:true}, editoptions:{size:10}, formoptions:{elmprefix:'*'}},
{name:'brname',index:'brname', width:100, editable:true, editrules:{required:true}, editoptions:{size:30}, formoptions:{elmprefix:'*'}},
{name:'bradd1',index:'bradd1', width:100, editable:true, editoptions:{size:30, maxlength:"60"}, edittype:'textarea'},
{name:'bradd2',index:'bradd2', width:100, editable:true, editoptions:{size:30}, formoptions:{elmprefix:'*'}},
{name:'brcity',index:'brcity', width:100, editable:true, editoptions:{size:20}, formoptions:{elmprefix:'*'}},
{name:'brpin',index:'brpin', width:50, editable:true, editoptions:{size:20}, formoptions:{elmprefix:'*'}},
{name:'bremail',index:'bremail', width:100, editable:true, editoptions:{size:30}, formoptions:{elmprefix:'*'}},
{name:'brcontactperson',index:'brcontactperson', width:100, editable:true, editoptions:{size:30}, formoptions:{elmprefix:'*'}}
],
gridview: true,
toolbar: [false, "bottom"],
pager: $('#pager'),
rowNum:3,
rowList:[1,2,3],
sortname: 'brcode',
sortorder: "asc",
viewrecords: true,
altRows: false,
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
imgpath: 'themes/basic/images',
caption: 'My JQGrid App',
onSelectRow: function(row_id){
if(row_id !== null) {
row_selected = row_id;
}
}
});
$("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,search:false,refresh:false},
{
beforeShowForm: function(form) {$('#brcode',form).hide();}
},
{
beforeShowForm: function(form) {$('#brcode',form).show();}
},
{
}
);
});
$.jgrid.edit = {
addCaption: "Add Branch Master",
editCaption: "Edit Branch Master",
bSubmit: "Submit",
bCancel: "Cancel",
bClose: "Close",
bYes : "Yes",
bNo : "No",
bExit : "Cancel",
closeAfterAdd:true,
closeAfterEdit:true,
reloadAfterSubmit:true,
msg: {
required: "is mandatory or required",
number: "is a number field. Enter a valid number",
minValue: "should not be less than ",
maxValue: "should not be more than "
},
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");
}
};
$.jgrid.del = {
caption: "Delete Branch Master",
msg: "Delete selected Branch?",
bSubmit: "Delete",
bCancel: "Cancel",
reloadAfterSubmit:true,
closeOnEscape:true,
onclickSubmit : function(eparams) {
var rowData = $("#list").jqGrid('getRowData', row_selected);
var retarr = {'brcode':rowData['brcode']};
return retarr;
}
};
我可以从异常中解释出响应对象没有正确返回&#34;行&#34;参数,但无法解决它。请帮忙。
答案 0 :(得分:0)
从Integer.parseInt抛出该异常,因此参数行或页面可能为null。 http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
更新: 这是出错的地方
rows = Integer.parseInt(request.getParameter("rows"));
int page = Integer.parseInt(request.getParameter("page"));
最简单的方法是更改为自动映射请求参数
public @ResponseBody BranchmstResponse getAll(
@RequestParam(value = "rows", required=false) Integer rows,
@RequestParam(value = "page", required=false) Integer page,
@RequestParam(value = "sidx", required=false) String sidx,
@RequestParam(value = "sord", required=false) String sord,
HttpServletRequest request){
// if (rows == null) ...