| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 951 人关注过本帖
标题:弱弱的问一个抛空指针的问题
取消只看楼主 加入收藏
fvplayboy
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-9-21
结帖率:0
收藏
 问题点数:0 回复次数:1 
弱弱的问一个抛空指针的问题
<%@ 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
快速回复:弱弱的问一个抛空指针的问题
数据加载中...
 
   



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

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