Here We are using orelly related jar(cos.jar) for uploading files
Maven pom.xml for cos.jar
<dependency>
<groupId>servlets.com</groupId>
<artifactId>cos</artifactId>
<version>05Nov2002</version>
</dependency>
Link for Direct jar Download:
http://www.servlets.com/cos/
Html Code:
<html>
<body>
<form name="fileUploadForm" method="POST" action="fu3" enctype="multipart/form-data">
<input type="file" name="fileUpload"/>
<input type="submit" value="Upload"/>
</form>
</body>
</html>
Web.xml:
<web-app>
<servlet>
<servlet-name>fu3</servlet-name>
<servlet-class>com.iton.FileUploadUsingOreilly</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fu3</servlet-name>
<url-pattern>/fu3</url-pattern>
</servlet-mapping>
</web-app>
Servlet Code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.oreilly.servlet.MultipartRequest;
public class FileUploadUsingOreilly extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException {
PrintWriter out=response.getWriter();
//We have to create the folder myfiles in c driver
MultipartRequest m=new MultipartRequest(request,"c:/myfiles");
out.write("Successfully Uploaded");
}
}
Output:
Maven pom.xml for cos.jar
<dependency>
<groupId>servlets.com</groupId>
<artifactId>cos</artifactId>
<version>05Nov2002</version>
</dependency>
Link for Direct jar Download:
http://www.servlets.com/cos/
Html Code:
<html>
<body>
<form name="fileUploadForm" method="POST" action="fu3" enctype="multipart/form-data">
<input type="file" name="fileUpload"/>
<input type="submit" value="Upload"/>
</form>
</body>
</html>
Web.xml:
<web-app>
<servlet>
<servlet-name>fu3</servlet-name>
<servlet-class>com.iton.FileUploadUsingOreilly</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fu3</servlet-name>
<url-pattern>/fu3</url-pattern>
</servlet-mapping>
</web-app>
Servlet Code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.oreilly.servlet.MultipartRequest;
public class FileUploadUsingOreilly extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException {
PrintWriter out=response.getWriter();
//We have to create the folder myfiles in c driver
MultipartRequest m=new MultipartRequest(request,"c:/myfiles");
out.write("Successfully Uploaded");
}
}
Output:
No comments:
Post a Comment