试试这个public String test (int s){
if (s != null){
try{
sql="select from table where id="+s;
...............
.............
}catch(Exception e){
System.err.outprintln(e.toString());
}
}else{
System.err.outprintln("int is null");
}
}
if (s != null){
try{
sql="select from table where id="+s;
...............
.............
}catch(Exception e){
System.err.outprintln(e.toString());
}
}else{
System.err.outprintln("int is null");
}
}
解决方案 »
- service无法进入到dao里面
- 问一个关于iframe的问题,请高手指教!!在线等
- 使用url传递参数怎么写?
- 高手本机运行没问题,到了服务器就不行了?
- 路过的大神帮忙看看HttpURLConnection异常
- access有没有jdbc连接呀?在线等待
- 如何得到Iterator中元素的个数?
- 请教:resin中web_inf/work目录下的文件是干什么用的,是临时文件吗?
- 请问哪有sql server 2000 for JDBC 的驱动(系统是Linux redhat8。0),在线等待。
- 新手学习JSP,请问要安装什么软件才能运行JSP程序?
- 我想做用JSP一个考试系统,但不知道怎么随机出题!请大家捧个场,给点意见吧……
- 我使用的是resin+jsp+oracle,出现了如下问题,请教??
if (s!=null)
或者
if (s==null)
都不可以,提示为Operator!=can not applied to int,null
public String test (int id){
....
....
return str;
}但用户一旦超时后,它的ID不是null了吗,这时程序当然会报错啊
程序报错不会是因为int的值问题,int即使不初始化,默认为0
[用户一旦超时后,它的id不是null了吗]这句话好象不成立.
指在session中,id就可能为null
此时i是0;
指在session中,id就可能为nullto:楼主
你确定id为int型?
public abstract Object getAttribute(String name)
getAttribute方法的Attribute Type是String型的呀。
参见
http://java.sun.com/products/servlet/2.1/api/javax.servlet.ServletRequest.html
<%
String id=sys.getSessionInfo(session,"UserID");
out.print(sendFile.getSendedFile(Integer.parseInt(id)))%>
在sendFile.java这个bean中:
public String getSendedFile(int userID) {
String sql;
int i=0;
String str = "";
try {
sql = "select * from SendFile where documented is null and userFrom=" + userID;
DBConnectionManager dm = DBConnectionManager.getInstance();
Connection con = dm.getConnection("gsweb");
Statement stmt = con.createStatement();
Statement stmt1 = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
......
......
......
dm.freeConnection("gsweb", con);
dm.release();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return str;
}如果用户没有登录之接运行jsp页,提示错误为
Internal Servlet Error:
javax.servlet.ServletException: nullRoot cause:
java.lang.NumberFormatException: null
系统一定会报错。但如果用object类型(java API类或用户定义类)就可以用null:
Object myObject = null; 将会通过编译。如果一定要用整型变量且用null表示为空,可用int的wrapper class Integer定义整型变量,具体如下:
Integer number = new Integer(9); 这样,当number没有被初始化或因某种原因丁一直为空时,就会返回null.
String id=sys.getSessionInfo(session,"UserID");
out.print(sendFile.getSendedFile(Integer.parseInt(id)))
%>
-------------------------------------------在String id=sys.getSessionInfo(session,"UserID");这句后加判断
if((s+"").equals("null"))......
int id=Integer.parseInt(sys.getSessionInfo(session,"UserID"));