request.getAttribute强制转换发生错误

  1.将request.getAttribute()强制转换为字符串

String a=(String)request.getAttribute("xinxi");

  单纯的将信息强制转换为字符串是没有错误的,如果对数据再加工,转换为整形等类型,那么就会出现错误

String a=(String)request.getAttribute("xinxi");
int b=Integer.parseInt(a);

2.需要通过toString()将数据转换为字符型,然后在进行整形的转换就不会有问题

String a=request.getAttribute("xinxi").toString();
int b=Integer.parseInt(a);

猜你喜欢

转载自blog.csdn.net/qq_43238335/article/details/106337536
今日推荐