2 caobaoyuan caobaoyuan 于 2016.04.30 03:07 提问

org.apache.jasper.JasperException:NumberFormat

图片说明
bug如图所示

org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "g_id"

public String selectApply1() throws Exception{
System.out.print("进入selectApplyGoods查看公司人员请购方法,");
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession(false);
System.out.println("获取session成功!");
User user = (User)session.getAttribute("user");
int uid = userService.uidUser(user);
System.out.print(uid+"huoqvle");
user.setU_id(uid);
applyGoodsLook = goodsService.selectApplyGoods(user);
System.out.print(applyGoodsLook);
return "apply_goods_success";
}

    public List<Map<String, Object>> selectApplyGoods(User user) throws Exception{
    System.out.print("进入selectApplyGoods请购商品查看service方法,");
    List<Map<String, Object>> applyGoodsLook = goodsDao.selectAppGoods(user);
    return applyGoodsLook;
}


public List<Map<String, Object>> selectAppGoods(User users) throws Exception{
    System.out.print("进入selectAppGoods请购Dao方法,");
    System.out.println(users.getU_id());
    String sql = "select t1.g_id,t1.g_gid,t1.g_name,t1.g_number,t1.g_price,t1.g_introduce,t1.g_state from tb_goods t1 left join user_goods t2 on t1.g_id=t2.g_id left join tb_user t3 on t2.u_id=t3.u_id where t1.g_state='已请购' and t3.u_id='"+users.getU_id()+"'";
    List<Map<String, Object>> query = this.getSession().createSQLQuery(sql).list();  
    /*String sql1 = "select g_id from user_goods where u_id='"+users.getU_id()+"'";
    Integer gid = ((Number)(this.getSession().createSQLQuery(sql1)).uniqueResult()).intValue();
    String sql2 = "select * from tb_goods where tb_goods.g_state='已请购' and tb_goods.g_id='"+gid+"'";
    List<Map<String, Object>> query = this.getSession().createSQLQuery(sql2).list();*/
    return query;
}

6个回答

CSDNXIAOS
CSDNXIAOS   2016.04.30 03:12

1、错误描述

2014-7-13 17:20:50 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [/FirstSSH] threw exception [/pages/student.jsp (line: ......
答案就在这里:org.apache.jasper.JasperException
----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?

w172087242
w172087242   Ds   Rxr 2016.04.30 09:57

你本来g_id可能对应的是一个数字类型的字段对吧;
但是可能是你在请求提交表单的时候直接传的是g_id的字面值,也就是字符串g_id;
导致struts2在给你格式化数字的时候出现数字格式化异常,因为"g_id"就不能转化成数字,所以可能是你表单的提交那里有问题;

具体情况你需要跟踪一下;

希望能帮到你

caobaoyuan
caobaoyuan   2016.04.30 11:12
<form action="Goods_sendApplyGoods" method="post">
<table>
        <tr>
            <td>请购ID</td>
            <td>请购物品ID</td>
            <td>请购物品名称</td>
            <td>请购物品数量</td>
            <td>请购物品价格</td>
            <td>请购物品介绍及备注</td>
            <td>请购物品状态</td>
        </tr>

        <c:forEach items="${applyGoodsLook}" var="appGoodLoBean1">
        <tr>
            <td>${appGoodLoBean1.g_id}</td>
            <td>${appGoodLoBean1.g_gid}</td>
            <td>${appGoodLoBean1.g_name}</td>
            <td>${appGoodLoBean1.g_number}</td>
            <td>${appGoodLoBean1.g_price}</td>
            <td>${appGoodLoBean1.g_introduce}</td>
            <td>${appGoodLoBean1.g_state}</td>      
            <td><button type="submit" value="确认">确 &nbsp; &nbsp; 认</button><td>
        </tr>
        </c:forEach>
        <button type="submit" value="确认">确 &nbsp; &nbsp; 认</button>
</table>
</form>
caobaoyuan
caobaoyuan   2016.04.30 11:15

获取的时候已经是int类型的了。 Goods good = new Goods();
good.setG_gid(request.getParameter("g_gid"));
System.out.println(good.getG_gid());
good.setG_name(request.getParameter("g_name"));
System.out.println(good.getG_name());
good.setG_price(Double.parseDouble(request.getParameter("g_price")));
System.out.println(good.getG_price());
good.setG_number(Integer.parseInt(request.getParameter("g_number")));
System.out.println(good.getG_number());
good.setG_introduce(request.getParameter("g_introduce"));
System.out.println(good.getG_introduce());
goodsService.applyGoods(user,good);

caobaoyuan
caobaoyuan   2016.04.30 11:14

获取的时候已经是int类型的了。 Goods good = new Goods();
good.setG_gid(request.getParameter("g_gid"));
System.out.println(good.getG_gid());
good.setG_name(request.getParameter("g_name"));
System.out.println(good.getG_name());
good.setG_price(Double.parseDouble(request.getParameter("g_price")));
System.out.println(good.getG_price());
good.setG_number(Integer.parseInt(request.getParameter("g_number")));
System.out.println(good.getG_number());
good.setG_introduce(request.getParameter("g_introduce"));
System.out.println(good.getG_introduce());
goodsService.applyGoods(user,good);

caobaoyuan
caobaoyuan   2016.04.30 11:15

我用的是struts、spring、hibernate技术

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!