本来我想将一组名字存到session里,服务器包错误,说是session不能写入,让我把一个 vo 序列化,等我序列化完,发现围绕着这个 vo 的所有页面都出毛病了,插入页面的提示column ‘’ cannot be null,查询的页面出现空指向异常,下午才做完的页面,现在好几个页面都没用了,这是怎么一回事啊??

解决方案 »

  1.   

    那是那个column为null把
    和Serializable没关系
    那接口只是一个类似标记的接口
      

  2.   

    不用序列化,你session的setAttribute那里的代码拿来看看。
      

  3.   

    值都取到了啊,那个path我怎么看都不可能没有值嘛,最后那句还是提示nullpointexception
    package com.ecjtu.servlet;import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.List;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import com.ecjtu.dao.DAOFactory;
    import com.ecjtu.model.DepartmentVo;
    import com.ecjtu.model.ManagerVo;public class DepartmentServlet extends HttpServlet { /**
     * Constructor of the object.
     */
    public DepartmentServlet() {
    super();
    } /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    } /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { this.doPost(request, response);
    } /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html");
    response.setCharacterEncoding("gb2312");
    PrintWriter out = response.getWriter();
    DepartmentVo department = new DepartmentVo();
    String path = null;
    List all = null;
    String method = request.getParameter("method");

    if("queryAllDepartment".equals(method)){
    try {
    all = new ArrayList();
    all = DAOFactory.getDepartmentDAOInstanse().queryAll();
    System.out.println("---------------->" + all.size());
    // request.setAttribute("department", all)
    request.setAttribute("department", all);
    } catch (Exception e) {
    e.printStackTrace();
    }
    path = "department_query.jsp";
    } else {
    path = "department_query.jsp";
    System.out.println("查询失败");
    String query_info = "修改失败";
    request.setAttribute("query_info", query_info);
    }

    if("insert".equals(method)) {
    String dt_name = request.getParameter("dt_name");
    String dt_createTime = request.getParameter("dt_createTime");
    String dt_bz = request.getParameter("dt_bz");

    department.setDt_name(dt_name);
    department.setDt_createTime(dt_createTime);
    department.setDt_bz(dt_bz);

    try {
    System.out.println(department.getDt_name());
    if(DAOFactory.getDepartmentDAOInstanse().insert(department)){
    String insert_info = "部门插入成功";
    path = "department_insert.jsp";
    request.setAttribute("insert_info", insert_info);
    } else{
    String insert_info = "部门插入失败";
    path = "department_insert.jsp";
    request.setAttribute("insert_info", insert_info);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    request.getRequestDispatcher(path).forward(request, response);
    }


    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
    // Put your code here
    }}
    package com.ecjtu.dao;import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import java.util.List;import com.ecjtu.model.DepartmentVo;public class DepartmentDAOImpl implements DepartmentDAO { @Override
    public boolean insert(DepartmentVo department) throws Exception {
    String sql = "INSERT INTO tb_department(dt_name,dt_createTime,dt_bz) VALUE(?,?,?) ";
    PreparedStatement pstmt = null;
    DataBaseConnection dbc = null;
    boolean flag = false;

    try {
    department = new DepartmentVo();
    dbc = new DataBaseConnection();
    pstmt = dbc.getConnection().prepareStatement(sql);
    pstmt.setString(1, department.getDt_name());
    pstmt.setString(2, department.getDt_createTime());
    pstmt.setString(3, department.getDt_bz());
    pstmt.executeUpdate();
    pstmt.close();
    flag = true;
    } catch (Exception e) {
    e.printStackTrace();
    }
    return flag;
    } @Override
    public List queryAll() throws Exception {
    List all = null;
    String sql = "SELECT id,dt_name,dt_createTime,dt_bz FROM tb_department";
    PreparedStatement pstmt = null;
    DataBaseConnection dbc = null;

    try {
    all = new ArrayList();
    dbc = new DataBaseConnection();
    pstmt = dbc.getConnection().prepareStatement(sql);
    ResultSet rs = pstmt.executeQuery();

    while(rs.next()) {
    DepartmentVo department = new DepartmentVo();
    department.setId(rs.getString(1));
    department.setDt_name(rs.getString(2));
    department.setDt_createTime(rs.getString(3));
    department.setDt_bz(rs.getString(4));
    all.add(department);
    }
    rs.close();
    pstmt.close();
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    dbc.close();
    }
    return all;
    }}
      

  4.   

                    try {
                        System.out.println(department.getDt_name());
                        if(DAOFactory.getDepartmentDAOInstanse().insert(department)){
                            String insert_info = "部门插入成功";
                            path = "department_insert.jsp";
                            request.setAttribute("insert_info", insert_info);
                        } else{
                            String insert_info = "部门插入失败";
                            path = "department_insert.jsp";
                            request.setAttribute("insert_info", insert_info);
                        }            
                    } catch (Exception e) {
                        e.printStackTrace();
                    }这里的try出错,你的path就是null
      

  5.   

    你的 tb_department表的id字段有没有设置成自增长?否则not null的错误很可能就是这里了。
      

  6.   

    加了啊,下午能运行的时候没加索引,后来加了个索引,然后把request改成了session,然后就没用了!!CREATE TABLE tb_department (
    id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    dt_name char(10) NOT NULL,
    dt_createTime varchar(20) NOT NULL,
    dt_bz varchar (50) NOT NULL
    ) AUTO_INCREMENT = 100; 
     create unique index tb_department on tb_department (dt_name);
      

  7.   

    request改成了session,然后就没用了!! request.getSession().setAttribute("insert_info", insert_info);
    这样有错?头一次见
      

  8.   

    这里没用session,我在那个类型为list的department加到了session里,然后就序列化,现在反正就插不进去了,只有等明天再找了,头都看晕了!