| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 953 人关注过本帖
标题:弱弱的问一个抛空指针的问题
只看楼主 加入收藏
fvplayboy
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-9-21
结帖率:0
收藏
 问题点数:0 回复次数:5 
弱弱的问一个抛空指针的问题
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.ResultSetMetaData"%>
<%! public boolean list(HttpServletRequest request,String drv,String url,String usr,
    String pwd,String username,String strPageSize,String strPageNo){
   
   
    try{
        Class.forName(drv).newInstance();
        Connection conn = DriverManager.getConnection(url,usr,pwd);
        Statement stm = conn.createStatement();
        
        int pageSize = Integer.parseInt(strPageSize);
        int pageNo = Integer.parseInt(strPageNo);
        int start = pageSize*(pageNo-1);
        
        String sql1 = "select count(*) as countall from address where username='"+username+"'";
                    
        ResultSet rs1= stm.executeQuery(sql1);
        if(rs1.next()){
            String countall = rs1.getString("countall");
            int rowCount = Integer.parseInt(countall);
            request.setAttribute("rowCount",rowCount);
            
            
            int pageCount = rowCount%pageSize==0?rowCount/pageSize:rowCount/pageSize+1;
            
            request.setAttribute("pageCount",pageCount);
            
            int pageFirstNo = 1;
            int pageLastNo = pageCount;
            int pagePreNo = pageNo>1?pageNo-1:1;
            int pageNextNo = pageNo<pageCount?pageNo+1:pageCount;
            
            request.setAttribute("pageFirstNo",pageFirstNo);
            request.setAttribute("pageLastNo",pageLastNo);
            request.setAttribute("pagePreNo",pagePreNo);
            request.setAttribute("pageNextNo",pageNextNo);        
        
        }
   
            rs1.close();
            
            
            String sql2 = "select * from address where username='"+username+"'order by name limit "+start+","+pageSize;
            List<Hashtable<String,String>> list = new ArrayList<Hashtable<String,String>>();
            ResultSet rs2 = stm.executeQuery(sql2);
            ResultSetMetaData rsmd = rs2.getMetaData();
            int cols = rsmd.getColumnCount();
            while(rs2.next()) {
                Hashtable<String,String> hash = new Hashtable<String,String>();
                for(int i=1;i<=cols;i++){
                String field = rsmd.getColumnName(i);
                String value = rs2.getString(i);
                if(value == null){
                    value="";
                }
                hash.put(field,value);
            }   
            
            list.add(hash);        
            
            }
            request.setAttribute("list",list);
            rs2.close();
            stm.close();
            conn.close();
            
   
    }catch(Exception e){
   
            e.printStackTrace();
            return false;
            
    }finally{}
    return true;
   
    }
   
   
%>
<%
    String drv ="com.mysql.jdbc.Driver";
    String url ="jdbc:mysql://localhost:3306/demo";
    String usr = "root";
    String pwd = "123";

%>
<%  
    String method = request.getParameter("method");
    String topage = "../adress.jsp";
    if(session.getAttribute("username")==null) {
        topage = "../login.jsp";        
    }else{   
        String username = (String)session.getAttribute("username");
        
        String pageSize = request.getParameter("pageSize");
        String pageNo = request.getParameter("pageNo");
        if(pageSize == null){
            pageSize = "25";            
        }
        if(pageNo == null){
            pageNo = "1";        
        }        
        request.setAttribute("pageSize",pageSize);
        request.setAttribute("pageNo",pageNo);
        
        if(method.equals("list")) {
        
             if(list(request,drv,url,usr,pwd,username,pageSize,pageNo));
            topage = "../address.jsp";
        
        }   
    }   
%>
<jsp:forward page="<%=topage %>"/>

好像是这句话引起的报错 为什么啊<jsp:forward page="<%=topage %>"/>

 
搜索更多相关主题的帖子: 指针 抛空 
2010-05-20 18:05
fvplayboy
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-9-21
收藏
得分:0 
哎呀 小兄疏忽了···总结的经验就是request用setAttribute存的不能用getParameter来取 这是取不到的
2010-05-21 13:09
檐語
Rank: 1
来 自:江西
等 级:新手上路
帖 子:9
专家分:2
注 册:2010-6-25
收藏
得分:0 
JAVA里可以用指针?

小小的天,大大的夢想。
2010-06-29 08:35
流星雨
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:JAVA风暴
等 级:版主
威 望:43
帖 子:1854
专家分:1868
注 册:2004-5-30
收藏
得分:0 
java不是没有指针,而是指针都被封装了。

感谢你们带我找到星空下美丽神话,无论经历多少苦痛也不放弃的梦;插上希望翅膀乘风我和你们飞翔,飞过海天尽头携手把梦想实现.....
2010-06-30 01:29
a123456v15
Rank: 2
等 级:论坛游民
帖 子:9
专家分:13
注 册:2009-9-21
收藏
得分:0 
呵呵,建议楼主在jsp页面中尽量少写java代码,使用jsp标签或EL表达式更好些,页面里面写多了java代码可维护性和可读性都不高,而且常常抛出一大堆问题,很难挑错
2010-07-21 21:22
chenyu329134
Rank: 2
等 级:论坛游民
帖 子:36
专家分:21
注 册:2010-9-17
收藏
得分:0 
用javaBean把java代码跟页面代码分开噻~!
2010-09-17 13:44
快速回复:弱弱的问一个抛空指针的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032035 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved