search

Home  >  Q&A  >  body text

java - SpringMvc没有根据&符号截取参数

  var url =  $('input[name="itemCode"]').val() +'/join.html?userid='+ $('input[name="userid"]').val()+'&telphone='+phone+'&axdversion='+ version +'&itemId='+ $('input[name="itemId"]').val();
  request.reqLocation(url);

Js中拼出了一个url,之后便跳转Url。其中

    reqLocation : function(url){            
        window.location = url;
    },

后端代码:

public ModelAndView registerHtml(String itemCode, Long itemId, Long userid, HttpServletRequest request,    HttpServletResponse response) {
       ......//业务代码
}

但是在有些情况下会由于参数问题报错:

【/item/zxyh/join.html】【{userid=14&itemCode=xyz&itemId=8:}】 java.lang.NullPointerException at channel.web.item.OpenItemController.down(OpenItemController.java:468) at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorIm

正确的应该像这样:

【/item/zxyh/join.html】【{itemId:123},{itemCode:xyz},{userid:1}】

springMVC 并没有根据&符号,将各种参数赋值。所以导致我的itemCode之类的参数为空。
js是手机端的,并且也只有少量请求会出现这种情况,想知道为什么,或者有没有人遇到同样的问题?

PHP中文网PHP中文网2802 days ago609

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:51:01

    Finally found the problem! !
    The cause of the problem should be a malicious attack, using a tool to inject parameters. It's not clear exactly how to do it.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:51:01

    @RequestParam

    Baidu’s

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:51:01

    This seems to have nothing to do with SpringMVC. If the itemId is not obtained in JS, the server side will naturally get NULL.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:51:01

    In the case of an error, check whether the parameter values ​​​​in the URL spelled out under front-end debugging are normal. The back-end check whether the request contains the above parameters and their values ​​

    reply
    0
  • Cancelreply