をダウンロードすることはできません。ServeltのcontextPathとのServletContextを使用して、任意のファイルのアップロード、ダウンロードに成功アップロードは、私が使用してファイルのアップロードを行って
ServletContext servletContext = getServletContext();
String contextPath = servletContext.getRealPath(File.separator);
String path = contextPath + "\\uploads\\" + session.getAttribute("seusername");
System.out.println(path);
File file=new File(path);
if(!file.exists())
file.mkdirs();
Part filePart = request.getPart("uploadfile");
//return content type of the file
String type = filePart.getHeader("content-type");
//checking content type of file.
if (!type.equals("application/x-msdownload")) {
final String fileName = getFileName(filePart);
myfilename=fileName;
try {
EncriptFilename= aESCryp.encrypt(fileName);
System.out.println(EncriptFilename);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStream fout = null;
InputStream filecontent = null;
try {
fout = new FileOutputStream(new File(path + File.separator + fileName));
filecontent = filePart.getInputStream();
int read = 0;
final byte[] bytes = new byte[32 * 1024];
while ((read = filecontent.read(bytes)) != -1) {
fout.write(bytes, 0, read);
}
fout.flush();
fout.close();
} catch (Exception er) {
System.out.println("error:"+er.getMessage());
}
}
私はそので結構です,,,画像、PDF、DOCファイルをアップロードしています。.. 後私のローカルディスクフォルダのファイルの場所。 D:\ JavaWorkspace.metadata.plugins \ org.eclipse.wst.server.core \ TMP1 \ wtpwebapps \ \アップロードファイル\ユーザー\のjava_coffee_cup_logo1600.png
私の質問は、このファイルをダウンロードする方法...である,, 、 hrefリンクではダウンロードできません。