关于for input String:""

IniTinlD 2012-03-23 12:52:31
页面代码:<script type="text/javascript" src="js/jquery-1.6.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
$(document).ready(function() {
initCommonJS();
$("#gridTable").datagrid({
url:'fetchShujiList.action?t=' + new Date(),
width:750,
sortName: 'name',
sortOrder: 'desc',
pagination:true,
rownumbers:true,
pageList:[15,30,50,100],
columns:[[
{field:'bookid',title:'书籍编号',width:30,hidden:true},
{field:'ck',checkbox:true,width:30},
{field:'bookname',title:'书籍名称',width:80,sortable:true},
{field:'autor',title:'作者',width:60,align:'center',sortable:true}
]],
toolbar:[{
id:'btnadd',
text:'添加',
iconCls:'icon-add',
handler:function(){
checkOpenUrl("#gridTable","shujidit.html",550,420,"添加","书籍");
}
},{
id:'btnremove',
text:'删除',
iconCls:'icon-remove',
handler:function(){
checkSelectSomeDoFunc("#gridTable","删除","书籍",
function(ids){
$.post("deleteShujis.action?selectedIds="+ids+"&t="+new Date(),{},function(result){
if (result=="success"){
$("#gridTable").datagrid("reload");
}else{
alert(result);
}
});
},
true
);
}
},{
id:'btnedit',
text:'修改',
iconCls:'icon-edit',
handler:function(){
checkSelectOneOpenUrl("#gridTable","shujidit.html",550,420,"修改","书籍");
}
}]
});
});

</script>
</head>
<body>
<table id="gridTable"></table>
</body>

Action内方法:
public void deleteShujis() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
try{
String[] ids = this.selectedIds.split(",");
for (int i=0;i<ids.length;i++){
this.shujiService.delete(Integer.valueOf(ids[i]));
}
response.getWriter().write("success");
}catch(Exception ex){
System.out.println(ex);
response.getWriter().write("删除书籍出错!");
}
}
数据库字段分别是
int bookid;
String bookname;
String autor;

错误信息:java.lang.NumberFormatException: For input string: ""

求解,哪里写的有问题
...全文
14189 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
木子哥 2014-05-12
  • 打赏
  • 举报
回复
今天我也遇到同样的错误,现吧解决方法说一下:action中的方法,吧一个list放入session中供页面调用 public void vstopicAction() { try { HttpServletRequest request = ServletActionContext.getRequest(); List<VSTopic> hb = vsTopicService.findVSTopic("0"); if (hb.size() > 0) { request.getSession().setAttribute("vstopic",hb); //request.setAttribute("vstopic", hb); } } catch (Exception e) { e.printStackTrace(); } } jsp: 前台获取这个session,并取出里面的值。 <c:forEach var="vstopic" items="${session.vstopic}" varStatus="status"> <tr> <td><a href=""><lable>${vstopic.tname}</lable></a></td> <td><a href=""><lable>${vstopic.tname}</lable></a></td> <td><a href=""><lable>${vstopic.tname}</lable></a></td> </tr> </c:forEach> -----以上写法报的错误和楼主一样,后台调试跟踪发现action中的那个list数据集存入session中后并不是一个对象,而是类似数组的方式,所以页面上直接${vstopic.tname} 这样写就会报错,修改成 ${vstopic.[0]} 就可以了。
tianyc 2012-07-17
  • 打赏
  • 举报
回复
吗的,都是来打酱油的,没有一个把问题解决的?草
IniTinlD 2012-03-23
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 x497347200 的回复:]
你看2楼和3楼叫你加的输出语句,主要是看那2条输出语句的结果 ,然后解决问题,其实猜都能猜到ids[i]有个值是空
[/Quote]
我知道是有个值为空,也按那加了然后输出的,可是输出的就是空白啊
X497347200 2012-03-23
  • 打赏
  • 举报
回复
你看2楼和3楼叫你加的输出语句,主要是看那2条输出语句的结果 ,然后解决问题,其实猜都能猜到ids[i]有个值是空
IniTinlD 2012-03-23
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 x497347200 的回复:]
引用 5 楼 initinld 的回复:
引用 1 楼 cai5 的回复:
Action内方法:
public void deleteShujis() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html……
[/Quote]
控制台输出的:
-----------

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

就是这样的= =
X497347200 2012-03-23
  • 打赏
  • 举报
回复
String[] ids = this.selectedIds.split(",");
for (int i=0;i<ids.length;i++){
this.shujiService.delete(Integer.valueOf(ids[i]));
}
你先输出selectedIds看看,再输出ids[i]看看 就能找到原因
hanson339751607 2012-03-23
  • 打赏
  • 举报
回复
这里报错了。Integer.valueOf(ids[i])
解决方法,加一个NumberFormatException异常处理

try{
Integer.valueOf(ids[i])
}catch(NumberFormatException e){
// 处理
}
X497347200 2012-03-23
  • 打赏
  • 举报
回复
selectedIds
String[] ids = this.selectedIds.split(",");
你把原始的selectedIds 输出来, 再把split后的ids[i] 遍历输出来看看,就能找到原因
X497347200 2012-03-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 initinld 的回复:]
引用 1 楼 cai5 的回复:
Action内方法:
public void deleteShujis() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
try……
[/Quote]
是让你看控制台的输出信息, 你把输出贴出来
alpha_423 2012-03-23
  • 打赏
  • 举报
回复
前台怎么拼装selectedIds的看的不是很明白。不过最保险的是在下面加个对id的验证
for (int i=0;i<ids.length;i++){
//TODO:验证一下id[i]是否合法
this.shujiService.delete(Integer.valueOf(ids[i]));
}
毛豆先生Max 2012-03-23
  • 打赏
  • 举报
回复
肯定是你页面传过来的值不对
你需要的是int型,结果你传了个""
所以出现了上述异常
IniTinlD 2012-03-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cai5 的回复:]
Action内方法:
public void deleteShujis() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
try{

System.out.pr……
[/Quote]
试了:
-----------

java.lang.NumberFormatException: For input string: ""
是不是哪里取值有问题的
IniTinlD 2012-03-23
  • 打赏
  • 举报
回复
[Quote=引用楼主 initinld 的回复:]
页面代码:<script type="text/javascript" src="js/jquery-1.6.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.j……
[/Quote]
试了:
-----------

java.lang.NumberFormatException: For input string: ""
还是这样...是不是那里取值有问题
菖蒲老先生 2012-03-23
  • 打赏
  • 举报
回复
this.shujiService.delete(Integer.valueOf(ids[i]));

肯定有一个ids[i]的值是"",
所以导致转换成int失败。
X497347200 2012-03-23
  • 打赏
  • 举报
回复
java.lang.NumberFormatException: For input string: "" 数据转换异常, 就一个地方
按楼上的,

this.shujiService.delete(Integer.valueOf(ids[i])); 前面再加个 System.out.println(ids[i]);
五哥 2012-03-23
  • 打赏
  • 举报
回复
Action内方法:
public void deleteShujis() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
try{

System.out.println("-----------" + this.selectedIds) ;//看看是什么结果
String[] ids = this.selectedIds.split(",");
for (int i=0;i<ids.length;i++){
this.shujiService.delete(Integer.valueOf(ids[i])); //应该是这里 ,"" == ids[i]
}
response.getWriter().write("success");
}catch(Exception ex){
System.out.println(ex);
response.getWriter().write("删除书籍出错!");
}
}

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧