本来我想将一组名字存到session里,服务器包错误,说是session不能写入,让我把一个 vo 序列化,等我序列化完,发现围绕着这个 vo 的所有页面都出毛病了,插入页面的提示column ‘’ cannot be null,查询的页面出现空指向异常,下午才做完的页面,现在好几个页面都没用了,这是怎么一回事啊??
解决方案 »
- 在spring中IOC注入的实例可以使用Object类型去接收吗
- 为什么我的EJB在JSP中无法引入
- 请问关于Struts与动态表单的问题
- Unreachable code
- myeclipse开发hibernate时出现得错误
- 请问在TOMCAT中,.JAVA和.CLASS文件应该放在哪个目录下?
- 求一本书的网址
- BMP中,ejbStore()是不是要显式调用的?
- struts中的中文问题: 表单(form) 分多页显示 为什么表单输入的中文信息 到下一个页面就变成了问号?
- struts中 简体中文转繁体中文问题!!高手求救!急!!!!
- Integer praseInt 如果输入是"1024MB" 怎样返回是1024而不是直接异常
- struts2 s:select怎样显示我想要显示的值
和Serializable没关系
那接口只是一个类似标记的接口
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;
}}
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
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);
这样有错?头一次见