jspsmart上传文件问题
发布网友
发布时间:2022-04-12 22:17
我来回答
共2个回答
热心网友
时间:2022-04-12 23:47
额,意思很明显,路径名称不可用。
也就是说,你要保存的这个路径有问题。我们写的有电不一样,不过你看看我咋写的:
<form
action="<%=request.getContextPath()%>/save.day05cjsp?username=<%=u.getUsername()%>"
method="post" enctype="multipart/form-data">
照片路径:
<input type="file" name="file1" />
<input type="submit" value="上传" />
</form>
private static void save(HttpServletRequest request,
HttpServletResponse response, String path) throws ServletException {
DiskFileItemFactory df = new DiskFileItemFactory();
ServletFileUpload su = new ServletFileUpload(df);
su.setSizeMax(500 * 1024);
String username = request.getParameter("username");
try {
List list = su.parseRequest(request);
for (int i = 0; i < list.size(); i++) {
FileItem fi = (FileItem) list.get(i);
if (!fi.isFormField()) {
String pic = fi.getName();
if (pic.length() > 90) {
// 数据库中存放文件名的列最大长度为90,为了向数据库存入文件名时不出现异常,所以在此过滤
request.getRequestDispatcher("/load.day05ujsp")
.forward(request, response);
return;
}
pid.save(new Pic(username, pic));
fi.write(new File(path + "/day05/" + username, pic));
}
}
request.getRequestDispatcher("/load.day05ujsp").forward(request,
response);
} catch (Exception e) {
e.printStackTrace();
}
}
热心网友
时间:2022-04-13 01:05
"The requested resource (/biyesheji/servlet/servletUpload) is not available"
你的servletUpload的设置不对。