我上傳文件,並且顯示它作爲一個鏈接...但最初當我加載它顯示一個空值的網頁...我想刪除此空值...如何刪除初始空值?
<form method="POST" name="form1" action="./FileUploadServlet" enctype="multipart/form-data" ><% String name= request.getParameter("name");%>File:
<input type="file" name="file" id="file" />
<input type="submit" value="Upload" name="upload" id="upload" />
<a href="./file/<%=name%>"><%=name%></a>
FileUploadServlet。 java
// Create path components to save the file
final String docs="C:\\Users\\tushar\\Documents\\NetBeansProjects\\fileupload\\web\\file\\";
final Part filePart = request.getPart("file");
final String file = getFileName(filePart);String a=request.getParameter("id");
OutputStream out = null;
InputStream filecontent = null;
final PrintWriter writer = response.getWriter(); try{
out = new FileOutputStream(new File(docs +""+file));
filecontent = filePart.getInputStream();
int read = 0;
final byte[] bytes = new byte[1024];
while ((read = filecontent.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
response.sendRedirect("upload.jsp?id="+a+"&name="+file+"");
// LOGGER.log(Level.SEVERE, "Problems during file upload. Error: {0}", new Object[]{fne.getMessage()});
} finally {
if (out != null) {
out.close();
}
if (filecontent != null) {
filecontent.close();
}
if (writer != null) {
writer.close();
}
只需在打印鏈接前檢查參數是否與null不同。 – 2013-03-11 04:45:33
其正確bcoz當我上傳一個文件,它來作爲一個鏈接... – user2154010 2013-03-11 04:55:39