`
sa364867195
  • 浏览: 6116 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Spring 之 @pathVariable @requestParam head-slapper

阅读更多
大家看看下面一段代码:
@RequestMapping(value = "/send", method = RequestMethod.POST)
public ModelAndView jmsSendHandler(@RequestParam String id, @RequestParam String value) throws Exception {
    System.out.println("POST MODEL: [" + id + "]");
    System.out.println("POST MODEL: [" + value + "]");
    DataBean dataBean = new DataBean(Integer.valueOf(id), value, new Date());
    messageProducer.sendMessage(dataBean);
    ModelAndView mav = new ModelAndView("sendseccess");
    mav.addObject("message", dataBean.toString());
    return mav;
}
这是一个Spring中的@Controller类的一个方法,我使用Junit用HttpUrlConnection模拟浏览器的行为来测试它没有问题.但当我用ant将其打成war包再发布到应用服务器(tomcat,glassfish)上去并访问它的时候出现如下异常:
No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
我用谷歌找到了解决方案:
http://www.objectpartners.com/2010/08/12/spring-pathvariable-head-slapper/
Thanks a lot
我将方法从
@RequestMapping(value = "/send", method = RequestMethod.POST)
public ModelAndView jmsSendHandler(@RequestParam String id, @RequestParam String value) throws Exception
改为
@RequestMapping(value = "/send", method = RequestMethod.POST)
public ModelAndView jmsSendHandler(@RequestParam("id") String id, @RequestParam("value") String value) throws Exception
如是运行正常了,
references:
http://www.ibm.com/developerworks/web/library/wa-spring3webserv/index.html
http://www.ibm.com/developerworks/web/library/wa-restful/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics