Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Form containing parameters not passed but file uploaded  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a webform on JSP page which has several parameters(strings and integers) values and a file to be uploaded to the server through a servlet. It is strange to see that i'm able to upload the file on to the server but not able to get the rest of the parameters in the servlet using request.getParameter("someString") Can anyone please find out the problem with my code or guide me?

<form method="POST" enctype="multipart/form-data" action="/cassino/uploadFile" >
<div class="form-group">
<label >*ID riparazione</label>

<input type="text" name="idRiparazione" />
<div class="form-group">
<label>*ID mandrino smontato</label>

<input type="text" name="idMandrinoSmontato" />
<div class="form-group">
<label>*Service livello(SL)</label>
<input type="text" name="serviceLivello" />
<div class="form-group">
<input type="file" name="attachment" class="" id="attach" />
<p class="text-right">
<input type="submit" value="Salva" name="newMacchina" />
<input type="reset" value="Cancella" />


@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;

* handles file upload via HTTP POST method
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// checks if the request actually contains upload file

String idRiparazione = request.getParameter("idRiparazione");
String idMandrinoSmontato = request.getParameter("idMandrinoSmontato");
String serviceLivello = request.getParameter("serviceLivello");

PrintWriter out = response.getWriter();
out.println("<h1>Hello Servlet Get</h1>");

DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(System.getProperty("")));

ServletFileUpload upload = new ServletFileUpload(factory);

// constructs the directory path to store upload file
String uploadPath = "C:\\SKFSFCassino\\uploads\\riparazione\\"; //getServletContext().getRealPath("") + File.separator + UPLOAD_DIRECTORY;
// creates the directory if it does not exist
File uploaddir = new File(uploadPath);

try {
List formItems = upload.parseRequest(request);
Iterator it = formItems.iterator();
// iterates over form's fields
FileItem item = (FileItem);
// processes only fields that are not form fields
if (!item.isFormField()) {
String fileName = new File(item.getName()).getName();
String filePath = uploadPath + File.separator + fileName;
File storeFile = new File(filePath);
// saves the file on disk
} catch (FileUploadException e) {
// TODO Auto-generated catch block
} catch (Exception e) {
// TODO Auto-generated catch block



public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, {
throw new ServletException("GET method used with " + getClass( ).getName( )+": POST method required.");
Ranch Hand
Posts: 645
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with multipart request you won't get get values using request.getParameter(). its discussed previously on java ranch here
ibrahim nadir
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank for the response. I have, however, already solved the problem since i couldn't wait to solve it. Thank you
I am mighty! And this is a mighty small ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!