I am uploading a file and displaying it as a link...but initially when I load the the page it displays a null value...I want remove this null value...
<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();
}