JSP中如何把图片复制到指写文件夹
- 提问者网友:我们很暧昧
- 2021-05-19 22:35
- 五星知识达人网友:想偏头吻你
- 2021-05-20 00:03
就是上传吗,
public ActionForward saveRole(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
Userinfo user = (Userinfo) session.getAttribute("user");
Role role=new Role();
Pacts pact=null;
response.setContentType("text/html");
String a="";
boolean isMultipart = FileUpload.isMultipartContent(request);
if (isMultipart) {
DefaultFileItemFactory factory = new DefaultFileItemFactory();
FileUpload upload = new FileUpload(factory);
Iterator items;
try {
items = upload.parseRequest(request).iterator();
while (items.hasNext()) {
FileItem item = (FileItem) items.next();
if (!item.isFormField()) {
try{
String name = item.getName();
String filename = name.substring(
name.lastIndexOf('\\') + 1, name.length());
String path = request.getRealPath("")
+ File.separatorChar +"\\upfile\\"+ filename;
File upfile = new File(path);
File file1=new File(request.getRealPath("")
+ File.separatorChar +"\\upfile\\");
file1.mkdir();
role.setFilename(filename);
role.setPath(path);
role.setContenttype(item.getContentType());
item.write(upfile);
}catch(Exception ex){
ex.printStackTrace();
}
}else{
if(item.getFieldName().equals("roleName")){
role.setRolename(item.getString("utf-8"));
}if(item.getFieldName().equals("remarks2")){
role.setFunctionrequest(item.getString("utf-8"));
}if(item.getFieldName().equals("id")){
pact=pactsService.findById(Integer.parseInt(item.getString()));
}if(item.getFieldName().equals("remarks")){
role.setViewrequest(item.getString("utf-8"));
}
}
}
role.setUsername(user.getAlias());
role.setBengintime(formart.format(date));
role.setEndtime(pact.getBegintime());
role.setUid(user.getId());
role.setPacts(pact);
role.setUid(user.getId());
roleService.save(role);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return mapping.findForward("disRol");
}
- 1楼网友:零点过十分
- 2021-05-20 00:24
上传源码我有的,并且可以使用,不过使用的Struts的,会配置Struts的话,你联系我QQ,我发你