servlet
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action=request.getParameter("action");
if(action==null)
{
action="";
}
if(action.equals("add"))
{
this.addnews(request, response);
}
}
public void addnews(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
RequestDispatcher rd=null;
CNews cmgbean=new CNews();
CNewsdao cmgdao=new CNewsdao();
cmgbean.setStr_NTitle(trans.toChinese(request.getParameter("ntitle")));
cmgbean.setStr_NTime(trans.toChinese(request.getParameter("ntime")));
cmgbean.setStr_NContent(trans.toChinese(request.getParameter("ncontent")));
boolean mark=cmgdao.operateNews("add",cmgbean);
if(!mark)
{
System.out.println("<script>alert('发布失败!!')</script>");
rd=request.getRequestDispatcher("../admin/login.jsp");
rd.forward(request, response);
}
else
{
response.sendRedirect("../admin/message.jsp");
}
}
}
数据库操作类
public boolean operateNews(String operation,CNews single)
{
String sql=null;
if(operation.equals("add"))
{
sql="insert into News values('"+single.getStr_NTitle()+"','"+single.getStr_NTime()+"','"+single.getStr_NContent()+"')";
//sql="insert into News values('"+single.getStr_NContent()+"','"+single.getStr_NTime()+"','"+single.getStr_NTitle()+"')";
}
if(operation.equals("modify"))
{
sql="update News set NTime='"+single.getStr_NTime()+"',NTitle='"+single.getStr_NTitle()+"',NContent='"+single.getStr_NContent()+"' where NId='"+single.getInt_Id()+"'";
}
if(operation.equals("delete"))
{
sql="delete from News where NId='"+single.getInt_Id()+"'";
}
boolean flag=connect.executeUpdate(sql);
return flag;
}
------解决方案--------------------
web.xml贴出来看看
------解决方案--------------------
------解决方案--------------------
boolean flag=connect.executeUpdate(sql);
connect.executeUpdate(sql)的返回值是影响的行数,怎么能用boolean接收呢?
------解决方案--------------------
at com.dao.CNewsdao.operateNews(CNewsdao.java:33)
很明显CNewsdao.java类的33行代码出错,在此类的operateNews方法中,可以去定位下那行代码,
看是调用其它方法还是方法内的错误。
------解决方案--------------------
唉!又是空指针···