fangyuan_luru.jsp at line 32 String ID=Encrypt.JM(r.substring(0,r.length()-10)); java.lang.NullPointerException JM 应该是 Encrypt 里面的静态方法,所以空指针就是r了 r 从 String r=request.getParameter("r"); 来的 检查 request.getParameter("r"); 的r 是否传过来?
String r=request.getParameter("r");是null吧
private void doInsertRentInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); String uID = request.getParameter("uID"); String dID = request.getParameter("dID"); String title = request.getParameter("title"); /*String districtID = request.getParameter("districtID");*/ String circleID = request.getParameter("circleID"); String community = request.getParameter("community"); String houseType = request.getParameter("houseType"); String floor = request.getParameter("floor"); String area = request.getParameter("area"); String direction = request.getParameter("direction"); String price = request.getParameter("price"); String hType = request.getParameter("hType"); String images = request.getParameter("images"); String description = request.getParameter("description"); String phone = request.getParameter("phone"); String contacts = request.getParameter("contacts"); String crtTime = request.getParameter("crtTime"); String status = request.getParameter("status"); String type = request.getParameter("type"); /*String userInfoID = request.getParameter("uID");*/ title = new String(title.getBytes("ISO-8859-1"), "utf-8"); /*districtID = new String(districtID.getBytes("ISO-8859-1"), "utf-8"); circleID = new String(circleID.getBytes("ISO-8859-1"), "utf-8");*/ community = new String(community.getBytes("ISO-8859-1"), "utf-8"); houseType = new String(houseType.getBytes("ISO-8859-1"), "utf-8"); floor = new String(floor.getBytes("ISO-8859-1"), "utf-8"); area = new String(area.getBytes("ISO-8859-1"), "utf-8"); direction = new String(direction.getBytes("ISO-8859-1"), "utf-8"); /*price = new String(price.getBytes("ISO-8859-1"), "utf-8");*/ hType = new String(hType.getBytes("ISO-8859-1"), "utf-8"); images = new String(images.getBytes("ISO-8859-1"), "utf-8"); description = new String(description.getBytes("ISO-8859-1"), "utf-8"); phone = new String(phone.getBytes("ISO-8859-1"), "utf-8"); contacts = new String(contacts.getBytes("ISO-8859-1"), "utf-8"); /*crtTime = new String(crtTime.getBytes("ISO-8859-1"), "utf-8"); status = new String(status.getBytes("ISO-8859-1"), "utf-8"); type = new String(type.getBytes("ISO-8859-1"), "utf-8");*/ /*userInfoID = new String(userInfoID.getBytes("ISO-8859-1"), "utf-8");*/ RentInfoDao rentInfoDao = new RentInfoDao(); RentInfo rentInfo = new RentInfo(); if (images.length() != 0) { try { // 文件上传目录“/file/news” String filepath = request.getSession().getServletContext() .getRealPath("/") + "file" + File.separator + "news"; // 文件上传临时目录“/file/temp” String tempPath = request.getSession().getServletContext() .getRealPath("/") + "file" + File.separator + "temp"; File dir = new File(filepath); // 建立目录 if (!dir.exists()) { dir.mkdirs(); } File dir1 = new File(tempPath); if (!dir1.exists()) { dir1.mkdirs(); } DiskFileUpload fu = new DiskFileUpload(); // 设置最大文件尺寸,这里是10MB fu.setSizeMax(10485760); // 设置缓冲区大小,这里是4kb fu.setSizeThreshold(4096); // 设置临时目录: fu.setRepositoryPath(tempPath); List fileItems = fu.parseRequest(request); Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String fileName = item.getName(); // 判断是否为文件 if (fileName != null) { // 取文件名 // String fname = // fileName.substring(fileName.lastIndexOf(File.separator)+1); String[] fname2 = fileName.split("[.]"); String fname = System.currentTimeMillis() + "." + fname2[1]; if (fileName != null && !fileName.equals("")) { File file = new File(filepath + File.separator + fname); // 上传文件 item.write(file); } images = "file/news/" + fname; rentInfo.setImages(images); } } } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } else{ rentInfo.setImages("http://guanghua.bagutech.com/guanghua/image/moren.jpg"); } rentInfo.setTitle(title); System.out.println(dID); rentInfo.setDistrictID(Integer.parseInt(dID)); if(!"".equals(circleID)){ rentInfo.setCircleID(Integer.parseInt(circleID)); } /* rentInfo.setDistrictID(Integer.parseInt(districtID)); rentInfo.setCircleID(Integer.parseInt(circleID));*/ rentInfo.setCommunity(community); rentInfo.setHouseType(houseType); rentInfo.setFloor(floor); rentInfo.setArea(area); rentInfo.setDirection(direction); rentInfo.setPrice(Double.parseDouble(price)); rentInfo.setHType(hType); rentInfo.setImages(images); rentInfo.setDescription(description); rentInfo.setPhone(phone); rentInfo.setContacts(contacts); /*rentInfo.setCrtTime(rentInfo.getCrtTime());*/ rentInfo.setStatus(Integer.parseInt(status)); rentInfo.setType(Integer.parseInt(type)); rentInfo.setUserInfoID(Integer.parseInt(uID)); int rows = rentInfoDao.insertRentInfo(rentInfo); if (rows > 0) { /*Logger log=new Logger(); LoggerDao logDao=new LoggerDao(); log.setDescrip("添加房源信息 "+rows); log.setType("2"); log.setOpID(Integer.parseInt(uID)); logDao.insertLogger(log);*/ String r = Encrypt.JM(dID + "") + Encrypt.Random(); out.print("<script type='text/javascript'>alert('房源信息添加成功!');location.replace('../manage/fangyuan_luru.jsp?r="+r+"');</script>"); } else { out.print("<script type='text/javascript'>alert('房源信息添加失败!');history.go(-1);</script>"); } }servlet的代码
看看Encrypt 、 r 有没有数据
在看看
String ID=Encrypt.JM(r.substring(0,r.length()-10));
java.lang.NullPointerException
JM 应该是 Encrypt 里面的静态方法,所以空指针就是r了
r 从 String r=request.getParameter("r"); 来的
检查 request.getParameter("r"); 的r 是否传过来?
HttpServletResponse response) throws ServletException, IOException{
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String uID = request.getParameter("uID");
String dID = request.getParameter("dID");
String title = request.getParameter("title");
/*String districtID = request.getParameter("districtID");*/
String circleID = request.getParameter("circleID");
String community = request.getParameter("community");
String houseType = request.getParameter("houseType");
String floor = request.getParameter("floor");
String area = request.getParameter("area");
String direction = request.getParameter("direction");
String price = request.getParameter("price");
String hType = request.getParameter("hType");
String images = request.getParameter("images");
String description = request.getParameter("description");
String phone = request.getParameter("phone");
String contacts = request.getParameter("contacts");
String crtTime = request.getParameter("crtTime");
String status = request.getParameter("status");
String type = request.getParameter("type");
/*String userInfoID = request.getParameter("uID");*/
title = new String(title.getBytes("ISO-8859-1"), "utf-8");
/*districtID = new String(districtID.getBytes("ISO-8859-1"), "utf-8");
circleID = new String(circleID.getBytes("ISO-8859-1"), "utf-8");*/
community = new String(community.getBytes("ISO-8859-1"), "utf-8");
houseType = new String(houseType.getBytes("ISO-8859-1"), "utf-8");
floor = new String(floor.getBytes("ISO-8859-1"), "utf-8");
area = new String(area.getBytes("ISO-8859-1"), "utf-8");
direction = new String(direction.getBytes("ISO-8859-1"), "utf-8");
/*price = new String(price.getBytes("ISO-8859-1"), "utf-8");*/
hType = new String(hType.getBytes("ISO-8859-1"), "utf-8");
images = new String(images.getBytes("ISO-8859-1"), "utf-8");
description = new String(description.getBytes("ISO-8859-1"), "utf-8");
phone = new String(phone.getBytes("ISO-8859-1"), "utf-8");
contacts = new String(contacts.getBytes("ISO-8859-1"), "utf-8");
/*crtTime = new String(crtTime.getBytes("ISO-8859-1"), "utf-8");
status = new String(status.getBytes("ISO-8859-1"), "utf-8");
type = new String(type.getBytes("ISO-8859-1"), "utf-8");*/
/*userInfoID = new String(userInfoID.getBytes("ISO-8859-1"), "utf-8");*/
RentInfoDao rentInfoDao = new RentInfoDao();
RentInfo rentInfo = new RentInfo();
if (images.length() != 0) {
try {
// 文件上传目录“/file/news”
String filepath = request.getSession().getServletContext()
.getRealPath("/")
+ "file" + File.separator + "news";
// 文件上传临时目录“/file/temp”
String tempPath = request.getSession().getServletContext()
.getRealPath("/")
+ "file" + File.separator + "temp";
File dir = new File(filepath);
// 建立目录
if (!dir.exists()) {
dir.mkdirs();
}
File dir1 = new File(tempPath);
if (!dir1.exists()) {
dir1.mkdirs();
}
DiskFileUpload fu = new DiskFileUpload();
// 设置最大文件尺寸,这里是10MB
fu.setSizeMax(10485760);
// 设置缓冲区大小,这里是4kb
fu.setSizeThreshold(4096);
// 设置临时目录:
fu.setRepositoryPath(tempPath); List fileItems = fu.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
String fileName = item.getName();
// 判断是否为文件
if (fileName != null) {
// 取文件名
// String fname =
// fileName.substring(fileName.lastIndexOf(File.separator)+1);
String[] fname2 = fileName.split("[.]");
String fname = System.currentTimeMillis() + "."
+ fname2[1];
if (fileName != null && !fileName.equals("")) {
File file = new File(filepath + File.separator
+ fname);
// 上传文件
item.write(file);
}
images = "file/news/" + fname;
rentInfo.setImages(images);
} }
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
else{
rentInfo.setImages("http://guanghua.bagutech.com/guanghua/image/moren.jpg");
}
rentInfo.setTitle(title);
System.out.println(dID);
rentInfo.setDistrictID(Integer.parseInt(dID));
if(!"".equals(circleID)){
rentInfo.setCircleID(Integer.parseInt(circleID));
}
/* rentInfo.setDistrictID(Integer.parseInt(districtID));
rentInfo.setCircleID(Integer.parseInt(circleID));*/
rentInfo.setCommunity(community);
rentInfo.setHouseType(houseType);
rentInfo.setFloor(floor);
rentInfo.setArea(area);
rentInfo.setDirection(direction);
rentInfo.setPrice(Double.parseDouble(price));
rentInfo.setHType(hType);
rentInfo.setImages(images);
rentInfo.setDescription(description);
rentInfo.setPhone(phone);
rentInfo.setContacts(contacts);
/*rentInfo.setCrtTime(rentInfo.getCrtTime());*/
rentInfo.setStatus(Integer.parseInt(status));
rentInfo.setType(Integer.parseInt(type));
rentInfo.setUserInfoID(Integer.parseInt(uID));
int rows = rentInfoDao.insertRentInfo(rentInfo);
if (rows > 0) {
/*Logger log=new Logger();
LoggerDao logDao=new LoggerDao();
log.setDescrip("添加房源信息 "+rows);
log.setType("2");
log.setOpID(Integer.parseInt(uID));
logDao.insertLogger(log);*/
String r = Encrypt.JM(dID + "") + Encrypt.Random();
out.print("<script type='text/javascript'>alert('房源信息添加成功!');location.replace('../manage/fangyuan_luru.jsp?r="+r+"');</script>");
} else {
out.print("<script type='text/javascript'>alert('房源信息添加失败!');history.go(-1);</script>");
}
}servlet的代码
out.print("<script type='text/javascript'>alert('房源信息添加成功!');location.replace('../manage/fangyuan_luru.jsp?r="+r+"');改为String r = Encrypt.JM(dID + "") + Encrypt.Random(); // 这一行不变
out.print("<script type='text/javascript'>alert('房源信息添加成功!');location.replace('../manage/fangyuan_luru.jsp?r='"+r+")");
试试
顺便说句,下次整理代码时,把代码整理好,这个太乱了
String r = Encrypt.JM(dID + "") + Encrypt.Random(); // 这一行不变
out.print("<script type='text/javascript'>alert('房源信息添加成功!');location.replace('../manage/fangyuan_luru.jsp?r='"+r+")")在String r = Encrypt.JM(dID + "") + Encrypt.Random(); 完了时,打印下r的值,看r值为多少?确保在这里的r非空