Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 675

GetParts() returning null in servlet [duplicate]

$
0
0

Hello guys i'm facing a problem with my code, i have a jsp form that send a file into a servlet, and when i try to extract the file using request.getParts() it return null value wheni try to print it to the console, can anyone help me please. here is my code.

my jsp:

<!DOCTYPE html><html lang="en"><head><title>File Upload</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><form method="POST" action="/PartsServlet" enctype="multipart/form-data">                File:<input type="file" name="file" id="file" /> <br/>                Destination:<input type="text" value="/tmp" name="destination"/></br><input type="submit" value="Upload" name="upload" id="upload" /></form></body></html>

My servlet:

package Servv;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet implementation class PartsServlet */@WebServlet("/PartsServlet")public class PartsServlet extends HttpServlet {    private static final long serialVersionUID = 1L;    /**     * @see HttpServlet#HttpServlet()     */    public PartsServlet() {        super();        // TODO Auto-generated constructor stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        response.getWriter().append("Served at: ").append(request.getContextPath());        System.out.println("Get Parts "+request.getPart("file"));        System.out.println("Get Parts "+request.getPart("destination"));    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}

Viewing all articles
Browse latest Browse all 675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>