先说明下需求,后台接收POST请求,返回json格式数据:
测试工具火狐插件:HTTP Requester
现在的问题是本地测试没有问题,但把程序部署到服务器上就报错;
代码如下:
@RequestMapping(value = "/login", method = RequestMethod.POST) @ResponseBody public Object login(@RequestParam String account, String pwd) { int result = -1; BasAccount ba = null; if (account != null && pwd != null) { result = basAccountService.login(account, pwd); }
Map map = new LinkedHashMap(); if (result == 1) { map.put("state", 1); map.put("id", Conversion.Bytes2HexString(ba.getId())); map.put("account", ba.getAccount()); return map; } }
@RequestMapping(value = "/login", method = RequestMethod.POST) @ResponseBody public Object login(@RequestBody BasAccount b) { String account = b.getAccount(); String pwd= b.getPwd(); int result = -1; BasAccount ba = null; if (account != null && pwd != null) { result = basAccountService.login(account, pwd); } Map map = new LinkedHashMap(); if (result == 1) { map.put("state", 1); map.put("id", Conversion.Bytes2HexString(ba.getId())); map.put("account", ba.getAccount()); return map; } }
请求映射里面加上consumes="application/json",produces="application/json;charset=UTF-8",也没效果;
返回的错误页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Oracle GlassFish Server 3.1.2.2 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><hr/><p><b>type</b> Exception report</p><p><b>message</b></p><p><b>description</b>The server encountered an internal error () that prevented it from fulfilling this request.</p><p><b>exception</b> <pre>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find operation.</pre></p><p><b>root cause</b> <pre>java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find operation.</pre></p><p><b>note</b> <u>The full stack traces of the exception and its root causes are available in the Oracle GlassFish Server 3.1.2.2 logs.</u></p><hr/><h3>Oracle GlassFish Server 3.1.2.2</h3></body></html>
另外,另一个接口:
@RequestMapping(value = "/advice", method = RequestMethod.POST) @ResponseBody public Map<String, Object> advice(@RequestParam String account, String advice) {
同样的写法,在服务器上这个是可以调通的
本地的数据库和服务器上的表、视图和存储过程都一样
求大神帮忙,问题是出在哪里呢?