0% found this document useful (0 votes)
7 views1 page

5b Code

The document contains a Java servlet class named UploadServlet that handles file uploads via HTTP POST requests. It uses the @MultipartConfig annotation for file handling and retrieves the uploaded file's details, including its name and destination path. Upon successful upload, it generates an HTML response indicating the filename and a success message.

Uploaded by

Abdulaziz Kanoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

5b Code

The document contains a Java servlet class named UploadServlet that handles file uploads via HTTP POST requests. It uses the @MultipartConfig annotation for file handling and retrieves the uploaded file's details, including its name and destination path. Upon successful upload, it generates an HTML response indicating the filename and a success message.

Uploaded by

Abdulaziz Kanoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]

You might also like