I am trying to use FormPanel. oN FormPanel
formPanel.setWidget(flexTable);
A check box , a listBox and FileUpload is added
flexTable.setWidget(4, 1,listBox);
flexTable.setWidget(5, 1, fileUpload);
flexTable.setWidget(6, 1, checkBox);
// More Code
A Servlet code is written to get the all the values which running fine only for fileUpload. How to get the value of checkBox an ListBox.
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
byte[] buffer = new byte[1310720];// 10 MB
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if (item.isFormField()) {
// WHAT TO DO??
} else {
int len;
while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
response.getOutputStream().write(buffer, 0, len);
}
}
}
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Plz help to get the value of checkBox and List Box.
See the answer to this question: Passing parameters along with a multipart/form-data upload form (Java Http Post Upload) on how to get the values on the server side.
To send the values to the server you need to set a name on each widget via the
setName()
method on the ListBox and CheckBox widgets. The name is whatitem.getFieldName()
returns.In What to do of your code.
and dont forget to
setName
of each widget on theFormpanel
Several things here:
checkbox.getElement().setAttribute("name", "mycheck");
) and in your servlet you get the value byrequest.getParameter("mycheck")
.