java - SpringMvc没有根据&符号截取参数
PHP中文网
PHP中文网 2017-04-18 10:49:01
0
4
572
  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中文网

认证0级讲师

reply all(4)
Ty80

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.

PHPzhong

@RequestParam

Baidu’s

左手右手慢动作

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

洪涛

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 ​​

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!