<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%
String strId = request.getParameter("id");
String strRoot = request.getParameter("rootid");
int id = Integer.parseInt(strId);
int rootId = Integer.parseInt(strRoot);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<form action="ReplyOK.jsp" method="post">
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootId" value="<%=rootId %>">
<table border="1">
<tr>
<td>
<input type="text" name="title" size=80>
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
pageEncoding="gbk"%>
<%
String strId = request.getParameter("id");
String strRoot = request.getParameter("rootid");
int id = Integer.parseInt(strId);
int rootId = Integer.parseInt(strRoot);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<form action="ReplyOK.jsp" method="post">
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootId" value="<%=rootId %>">
<table border="1">
<tr>
<td>
<input type="text" name="title" size=80>
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
String strId = request.getParameter("id");
String strRoot = request.getParameter("rootid");
int id = Integer.parseInt(strId);
int rootId = Integer.parseInt(strRoot);
[/code
觉得上面的这里可能会出错!
当你strId,strRoot没有值的时候会出错。因为在没有值的情况下,你把一个空对象的转换成Interger类型,这样显然会抱错!你还是在转换前,加以判断!
例如: request.getParameter("rootid") 是否等于null
int id = Integer.parseInt(strId);
int rootId = Integer.parseInt(strRoot);加上try异常处理!!!
String strRoot = request.getParameter("rootid");你要确定这两个取到值才能接下来的类型转换
你用 System.out.println(strId);
System.out.println(strRoot);
打出来看看,取到的是什么
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
改成
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<input type="hidden" name="id" value="<%=id %>">
应该改为:<input type="hidden" name="id" value="<%=strid %>">
<input type="hidden" name="rootId" value="<%=rootId %>">如果strId、strRoot都是整数,都改成
<input type="hidden" name="id" value="<%=strId %>">
<input type="hidden" name="rootId" value="<%=strRoot %>">
这样就可以了,不用再转换类型多此一举
int rootId = Integer.parseInt(strRoot);
这2名前先加以判断strId,strRoot是否为null呗,或者用try catch括起来
int id,rootId;
try{
id = Integer.parseInt(strId);
rootId = Integer.parseInt(strRoot);
}
catch{
id = 0;
rootId = 0;
}
String strRoot = request.getParameter("rootid");在第一次加载的时候获得的 strId,strRoot都是null 所以在后面转换成数字的时候抛出了异常
String strRoot = request.getParameter("rootid");
int id = Integer.parseInt(strId);
int rootId = Integer.parseInt(strRoot);第一次加载的时候获取到null值,之后就会报类型转换的错误了。
pageEncoding="gbk"%>需设两个“gbk”吗???
String str = "shit";
int num = Integer.parseInt(str);