I have a webform on JSP that has several string values and a file uploaded to the server through a servlet. It is strange to see that I can upload the file to the server, but I can’t get the values in the servlet using request.getParameter("someString") .
What is the problem with my code or manual?
EDIT: With a little research, I found out that if I use enctype="multipart/form-data" in the form tag, I cannot get the parameters into the servlet using request.getParameter() . The question may now be how can I send the file and other values to the servlet for processing.
webform.jsp
<form method="POST" enctype="multipart/form-data" action="/cassino/uploadFile" > <fieldset> <div class="form-group"> <label >*ID riparazione</label> <input type="text" name="idRiparazione" /> </div> <div class="form-group"> <label>*ID mandrino smontato</label> <input type="text" name="idMandrinoSmontato" /> </div> <div class="form-group"> <label>*Service livello(SL)</label> <input type="text" name="serviceLivello" /> </div> <div class="form-group"> <label>Attachment</label> <input type="file" name="attachment" class="" id="attach" /> </div> </fieldset> </div> <p class="text-right"> <input type="submit" value="Salva" name="newMacchina" /> <input type="reset" value="Cancella" /> </p> </form>
And uploadFile.java
@WebServlet( name = "uploadFile", urlPatterns = { "/uploadFile" } ) public class uploadFile extends HttpServlet { private static final long serialVersionUID = 1L; private static final int THRESHOLD_SIZE = 1024 * 1024 * 3; private static final int MAX_FILE_SIZE = 1024 * 1024 * 15; private static final int MAX_REQUEST_SIZE = 1024 * 1024 * 20; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
I don't think there might be a display issue, but I'm a little confused by this because my web.xml does not show any mapping or servlet. However, the servlet uploaded the file and returned the following result:
Hello Servlet Get null null
source share