Its probably a multipart message :S
Try googling for how to accept multipart message on the server side
here is some example but i don't know if you find usefull.
public HashMap<String, InputStream> parseMultipartMessage(
HttpServletRequest request) {
mapWithStreams = new HashMap<String, InputStream>();
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
try {
if (isMultipart) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
for (FileItem item : items) {
mapWithStreams.put(item.getFieldName(), item.getInputStream());
}
} else {
mapWithStreams.put(DEFAULT_KEY, request.getInputStream());
}
} catch (FileUploadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return mapWithStreams;
In normal message (not multipart) data from the text fields come like
the body of the message. If you try to transfer file in normal message
then Stream is send like the body of the message. So you can transver
only Parameters or only stream. If you want to transfer parameters and
stream in same message you need to use multipart message. In multipart
message InputStream come on server like a body of the message. If that
input stream contain multipart message you need to parse that message.
So in one part you will have values from input fields and in other part
you will have Stream for uploaded file. Read about multipart messages on
the wiki site. Code abowe will parse all input streams from multipart
message and place them to the HasMap. The Key in HashMap is the File
name. You can access to streams later when you need them. To the
parameters you can access on the same way like you deed before:
request.getParameter("parameterName");
Good luck.
YoeZ wrote:
> Hey abhiram,
>
> I still have a problem in server side,, can you tell me how to catch
> variable from client.
>
> Let say I have a textbox in client.
>
> Textbox txtComment = new Textbox;
> txtComment.setName("txtComment");
> txtComment .setText("hello");
>
> in server side:
> I've tried:
> String varXXX = (String) request.getParameter("txtComment");
>
> but that's not working. :(
>
> and I've also tried like this :
>
> try {
> List items = upload.parseRequest(request);
> Iterator it = items.iterator();
> while (it.hasNext()) {
> FileItem item = (FileItem) it.next();
> if (item.isFormField()) {
> String name = item.getFieldName();
> if (name.equals("txtComment")) {
> ret = item.getString();
> }
> return ret;
> }
> }
> } catch (FileUploadException e) {
> return null;
> }
>
> but still null return.
>
> can you tell me how to catch it.
>
> regards
>
>
>
>
> On Oct 21, 12:32 am, abhiram wuntakal <[email protected]> wrote:
>
>> Hey Yoez,
>>
>> Not sure if it helps. But i have a workaround solution for this. Make it a
>> two-step process. First use a RemoteServiceServlet to pass across your
>> variables to the server side and then save these values into some variables
>> on the server side.
>>
>> Then you can use a HTTPServlet to pass across your file contents to the
>> server side. Now you have the file as well as the variables.
>>
>> HTH,
>> Cheers,
>> Abhiram
>>
>>
>>
>> On Mon, Oct 19, 2009 at 6:12 PM, YoeZ <[email protected]> wrote:
>>
>>
>>> thanks ian,, but i'm using GWT and tried to uploadfile which is must
>>> using FormPanel.
>>> I have successfully upload my file to server with UploadFile widget,
>>> but I have another textboxes too. and dunno how to catch inside
>>> FormPanel.
>>>
>>> On Oct 19, 7:15 pm, Ian Bambury <[email protected]> wrote:
>>>
>>>> You'll stand more chance of an answer if you ask that question in a Java
>>>> forum. This is a GWT group.
>>>> Ian
>>>>
>>>> http://examples.roughian.com
>>>>
>>>> 2009/10/19 YoeZ <[email protected]>
>>>>
>>>>> hello... please help
>>>>>
>>>>> On Oct 18, 12:31 am, YoeZ <[email protected]> wrote:
>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> I have 1 form panel with some textboxes and file upload.
>>>>>> the question is, how to get variables from client/form panel in
>>>>>> servlet?
>>>>>> i created DTO/Pojo object to hold variables in client, but i donk
>>>>>>
>>> know
>>>
>>>>>> how to catch in servlet..
>>>>>>
>>>>>> please help
>>>>>>
>>>>>> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---