我现在有两个参数deptId和deptId1需要传到servlet中去,传过去的是数字,以下是传参的语句和servlet中的代码,系统老报错java.lang.NumberFormatException: null,请问一下错在哪里啊,小弟是个新手,正处在摸索当中啊,谢谢了
onchange="window.location=('/servlet/SelectServlet3?deptId='+this.options[this.selectedIndex].value+'')"
onchange="window.location=('/servlet/SelectServlet3?deptId1='+this.options[this.selectedIndex].value+'')"
-------------------------------------
servlet中的代码:
public class SelectServlet3 extends HttpServlet {
public void destroy() 
 {
    super.destroy(); 
 }

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException 
 {
    doPost(request, response);
 }
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException 
 {
    String action = request.getParameter("action");
    DbUtil3 db = new DbUtil3();
    if("dept".equals(action))
    {
List depts = db.findAllDept();
request.setAttribute("depts", depts);
request.getRequestDispatcher("/deptList1.jsp").forward(request, response);
    }
    else{
 int deptId = Integer.parseInt(request.getParameter("deptId"));
 int deptId1 = Integer.parseInt(request.getParameter("deptId1"));
 List a1 = db.finda1ByDeptId(deptId,deptId1);
 request.setAttribute("a1", a1);
         request.getRequestDispatcher("/show.jsp").forward(request, response);
}
 }
-------------------------------------
public List finda1ByDeptId(int deptId,int deptId1){
List a1 = new ArrayList();
Connection conn = null;
PreparedStatement stmt = null;
PreparedStatement stmt1 = null;
ResultSet rs = null;
try {
String sql = "select ID, 标题, 内容 from 学生 where 所属库别 = ?";
String sql1 = "select ID, 标题, 内容 from 学生 where 所属库别 = ?";
conn = this.getConnection();
stmt = conn.prepareStatement(sql);
stmt1 = conn.prepareStatement(sql1);
stmt.setInt(1,deptId);
stmt1.setInt(1,deptId1);
rs = stmt.executeQuery();
while(rs.next()){
Info a1 = new Info();
raw.setId(rs.getInt("ID"));
raw.setTitle(rs.getString("标题"));
raw.setContent(rs.getString("内容"));
raws.add(raw);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeResultSet(rs);
this.closeStatement(stmt);
this.closeConnection(conn);
}
return raws;
}

解决方案 »

  1.   

    本帖最后由 net_lover 于 2009-07-30 15:17:03 编辑
      

  2.   

    onchange="window.location.href='/servlet/SelectServlet3?deptId='+this.options[this.selectedIndex].value" 
      

  3.   

    <select onchange="window.location.href='/servlet/SelectServlet3?deptId='+this.options[this.selectedIndex].value;">
    </select>
      

  4.   

    String idStr1 = request.getParameter("deptId"); 
    String idStr2 = request.getParameter("deptId1"); if(idStr1!=null&&idStr2!=null&&idStr1.trim().length()>0&&idStr2.trim().length()>0){
      int dId1 = Integer.parseInt(idStr1);
      int dId2 = Integer.parseInt(idStr2);
    }
      

  5.   

    在servlet中设断点调试一下,看deptId,deptId1的值是不是传过来了