C:/Users/kanoo/OneDrive/Documents/NetBeansProjects/UploadFile5a/src/java/p1/UploadServlet.
java
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package p1;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link].*;
@WebServlet(name = "UploadServlet", urlPatterns = {"/UploadServlet"})
@MultipartConfig//annotation used for file handling
/**
*
* @author kanoo
*/
public class UploadServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
String path = [Link]("destination");
Part filePart = [Link]("file");//method used to get all
details of file (such as type, name, location, etc)
String filename = [Link]();
[Link]("<!DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>File Uploaded</title>");
[Link]("</head>");
[Link]("<body bgcolor=lightgreen>");
[Link]("<h2>Filename: " + filename);
[Link]("</h2>");
[Link]("</body>");
[Link]("</html>");
try {
OutputStream os = new FileOutputStream(new File(path +
[Link] + filename));
InputStream is = [Link]();
int read;
while ((read = [Link]()) != -1) {
[Link](read);
}
[Link]("File Uploaded Successfully!!!!");
} catch (FileNotFoundException e) {
[Link](e);
}
}
}
1.1 of 1 2025.01.30 [Link]