PrintWriter p = response.getWriter();
if(servletPath.equals("/admin/categories/save")) {
if(session.getAttribute("admin") != null && session.getAttribute("admin").equals("true")) {
Category category = new Category();
MultipartRequest multi = new MultipartRequest(request, "/home/buzz/NetBeansProjects/bweb/web/images/");
category.setName(multi.getParameter("newName"));
category.setDescription(multi.getParameter("newDesc"));
File f = multi.getFile("newLogo");
String fileName = multi.getFilesystemName("newLogo");
category.setImgPath(fileName);
category.save();
}
}
else if(servletPath.equals("/admin/categories/update")) {
if(session.getAttribute("admin") != null && session.getAttribute("admin").equals("true")) {
Category category = new Category();
MultipartRequest multi = new MultipartRequest(request, "/home/buzz/NetBeansProjects/bweb/web/images/");
category.setId(new Integer(multi.getParameter("editId")));
category.setName(multi.getParameter("editName"));
category.setDescription(multi.getParameter("editDesc"));
String fileName = multi.getFilesystemName("editLogo");
File f = null;
if(fileName == null || fileName.equals("")) {
fileName = multi.getParameter("oldLogo");
}
else {
f = multi.getFile("editLogo");
}
category.setImgPath(fileName);
category.update();
}
}
response.sendRedirect(request.getContextPath() + "/admin/categories");
}