BeanUtils.populate(p, map)抛出ClassNotFoundException,请大侠知道。。。。
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletEx...
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Map<String,String[]> map = new HashMap<String,String[]>();
DiskFileItemFactory df = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(df);
sfu.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = new ArrayList<FileItem>();
try {
fileItems = sfu.parseRequest(request);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(FileItem fi : fileItems){
if(fi.isFormField()){
String name = fi.getFieldName();
String value = fi.getString("UTF-8");
map.put(name, new String[]{value});
}else{
String dir = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String path = "upload"+File.separator+"productImg"+File.separator+dir;
File file = new File(this.getServletContext().getRealPath(path));
if(!file.exists()){
file.mkdirs();
}
String imgName = fi.getName();
imgName = FilenameUtils.getName(imgName);
imgName = UUID.randomUUID().toString()+"-"+imgName;
try {
fi.write(new File(file,imgName));
String name = fi.getFieldName();
//map.put(name, new String[]{path+File.separator+imgName});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Product p = new Product();
p.setId(ProductId.getProductId());
try {
BeanUtils.populate(p, map);
request.getRequestDispatcher("admin/products/list.jsp").forward(request, response);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} 展开
throws ServletException, IOException {
Map<String,String[]> map = new HashMap<String,String[]>();
DiskFileItemFactory df = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(df);
sfu.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = new ArrayList<FileItem>();
try {
fileItems = sfu.parseRequest(request);
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(FileItem fi : fileItems){
if(fi.isFormField()){
String name = fi.getFieldName();
String value = fi.getString("UTF-8");
map.put(name, new String[]{value});
}else{
String dir = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String path = "upload"+File.separator+"productImg"+File.separator+dir;
File file = new File(this.getServletContext().getRealPath(path));
if(!file.exists()){
file.mkdirs();
}
String imgName = fi.getName();
imgName = FilenameUtils.getName(imgName);
imgName = UUID.randomUUID().toString()+"-"+imgName;
try {
fi.write(new File(file,imgName));
String name = fi.getFieldName();
//map.put(name, new String[]{path+File.separator+imgName});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Product p = new Product();
p.setId(ProductId.getProductId());
try {
BeanUtils.populate(p, map);
request.getRequestDispatcher("admin/products/list.jsp").forward(request, response);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询