Hi!

My code here:

gwt.xml:

      <servlet path="/uploader"
class="org.museum.laczkodezso.server.FileUploadHandlerServlet" />

client side code:

                final FormPanel formPanel = new FormPanel();
                formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
                formPanel.setMethod(FormPanel.METHOD_POST);
                formPanel.setAction(GWT.getModuleBaseURL() + "/uploader");

                VerticalPanel panel = new VerticalPanel();
                formPanel.setWidget(panel);


               // Create a FileUpload widget.
               FileUpload upload = new FileUpload();
               upload.setName("uploadFormElement");
               panel.add(upload);

            // Add a 'submit' button.
            panel.add(new Button("Submit", new ClickListener() {
                public void onClick(Widget sender) {
                  formPanel.submit();
                  Window.alert("submit");
              }
            }));

            formPanel.addFormHandler(new FormHandler() {
              public void onSubmit(FormSubmitEvent event) {
              }

              public void onSubmitComplete(FormSubmitCompleteEvent event) {
                Window.alert(event.getResults());
              }
            });


        initWidget(panel);

servlet code:

        public void doPost(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException {
                        try {
                                DiskFileItemFactory diskFileItemFactory = new 
DiskFileItemFactory
();
                                diskFileItemFactory.setSizeThreshold(40960); /* 
the unit is bytes
*/
                                
diskFileItemFactory.setRepository(repositoryPath);
                                ServletFileUpload servletFileUpload = new 
ServletFileUpload
(diskFileItemFactory);
                                servletFileUpload.setSizeMax(81920); /* the 
unit is bytes */
                                List<FileItem> fileItemsList = (List<FileItem>)
servletFileUpload.parseRequest(request);
                                Iterator<FileItem> it = 
fileItemsList.iterator();
                                while (it.hasNext()){
                                        FileItem fileItem = it.next();
                                        if (fileItem.isFormField()){
                                                /* The file item contains a 
simple name-value pair of a form
field */
                                                continue;
                                        } else{
                                                /* The file item contains an 
uploaded file */
                                                File file = new 
File(fileItem.getName());
                                        String fileName = file.getName();
                                        file = new 
File(repositoryPath.getAbsolutePath() + "/" +
fileName);
                                        fileItem.write(file);
                                        }
                                }
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
                        try {
                            out = response.getWriter();
                            out.println("success");
                        } catch (IOException e) {
                                e.printStackTrace();
                        }

         }

Please help me, you can.

thanks



On Apr 4, 3:35 pm, milcsi04 <milcs...@gmail.com> wrote:
> Hi All!
>
> Please help me, if you can.
> I created an app with GWT, where i've a form, which call a non gwt
> servlet,
> because i want to upload files with using this form.
> I tried so many example from the net, where they upload files.
> My problem with this, the client code seems not to call the servlet.
> It's do nothing when i click the submit. I defined the servlet in the
> gwt xml properly, but do nothing. My servlet create logs to database,
> but nothing happens when i call submit.
>
> I tried another way, i'm used RequestBuilder, and this called the
> servlet properly, and received the response object, but form can't
> send data to servlet. The parameter map is null. I don't understand
> it.
> I tried in hosted mode.
>
> Do you have an idea?
>
> This is very important for me.
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to