怎么改这个,小白请教
package news;
import java.io.*;
import
java.io.IOException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AdminAction extends HttpServlet{
PrintWriter out;
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws
IOException
{
response.setContentType("text/html;charset=gb2312");
out=response.getWriter();
HttpSession session=request.getSession(false);
int adminid=(Integer)session.getAttribute("adminid");
int power=(Integer)session.getAttribute("power");
StrEncode SE=new StrEncode();
String nid=request.getParameter("nid");
int nnid = Integer.parseInt(nid);
String cid=request.getParameter("cid");
String action=request.getParameter("action");
DBConn conn=new DBConn();
try{
NewsAdmin NA=new NewsAdmin();
if(action.equals("1")){
if (NA.canAdmin(adminid, nnid) || power > 10) {
NA.DeleNews(nnid);
response.sendRedirect("index.jsp");
}
else{
out.print("你无权操作!");
}
}
if(action.equals("2")){
int ccid=Integer.parseInt(cid);
if (power > 10) {
NA.DeleComm(ccid);
response.sendRedirect("shownews.jsp?nid="+nid);
}
else{
out.print("你无权操作!");
}
}
}
catch(Exception e){
out.print("发表评论写入数据库失败!"+e.toString());
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
doPost(request, response);
}
}
------解决方案--------------------int ccid=Integer.parseInt(cid);
这句话在cid不为空的情况下是可以转换的,否则就出现你的问题。过滤下为空的情况再转换。
------解决方案-------------------- int nnid = Integer.parseInt(nid);
int ccid=Integer.parseInt(cid);
这里面的nid或者cid可能是null值,你强制转换前先判断是否是null值
------解决方案--------------------转换之前要把这种情况考虑进去处理一下,数据保护,
------解决方案--------------------String nid