弱弱的问一个抛空指针的问题
<%@ 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 %>"/>