java.lang.NumberFormatException: For input string: " 2"

解决办法(有点low哈哈哈)

    String id = String.format("%s", request.getParameter("productId"));
    int realId = Integer.parseInt(id.replaceAll(" ", ""));
    /*
    这里用realId获取商品的id。

    直接用request.getParameter("productId")获取从上一个JSP页面传过来的id的话,
    会报一个   java.lang.NumberFormatException: For input string: " 2"  的错误,
    错误原因不明,这里用String类的replaceAll()将传过来的参数中的空格去掉了
     */