Posts

Showing posts from March, 2014

How to upload file using Servlet of Java in NetBeansIDE

Image
How to upload file using Servlet of Java in NetBeansIDE How to upload file using Servlet of Java in NetBeansIDE 1. Open NetBeansIDE. 2. Make a new Java web project. 3. Make a form in index.jsp (method='POST', enctype='multipart/form-data'). 4. Make a servlet(FileUploadServlet) in source package folder and add it to deployment    descriptor(web.xml). 5. Copy this process request method code in your servlet. protected void processRequest(HttpServletRequest request,         HttpServletResponse response)         throws ServletException, IOException {     response.setContentType("text/html;charset=UTF-8");     final String path = request.getParameter("destination");     final Part filePart = request.getPart("file");     final String fileName = getFileName(filePart);     OutputStream out = null;     InputStream filecontent = null;     final PrintWriter writer = response.getWriter();