i have got a situation now.
I need to develop a webpage where user can select a file to upload and before uploading the file to server i need to check first few lines of the file whether the data is valid or not and if the data is valid then upload the file, if not through an error message.
the file will be text file.
thanks,
Sandeep
HTML/Javascript does not offer a way of reading the contents of a local file. You must either upload it and check it in the server.
If you really want a client side check, you then must build a signed applet(or even ActiveX) to run in your webpage and handle the upload instead of using plain HTML.
You should perform your validation on the server side, right before you perform the upload.
Related
My requirement is to export an excel from GWT application on click of export button. In my case There is no need to send data from client to server as I can directly obtain data from database(same data is being populated on the client that is being exported).
All I tried to send a RPC call from Client site . but I am not able to figure out how to export excel on receiving the RPC call at server site.
This is certainly possilbe 100% client side.
You can use an Excel JavaScript builder like https://github.com/stephenliberty/excel-builder.js and call it from GWT with jsni or jsinterop.
Later you can save the file by
For Internet explorer for example filesaver.js https://github.com/eligrey/FileSaver.js/ in the same way.
For other browsers using HTML5 downloadv (using FileDownloadBuilder.createFileDownload().generateTextDownloadLink()) from https://github.com/akjava/html5gwt
Note for the generating an Excem file you could also just create an html file with table tags and save it as .xls, it with filesaver.js.
I use the html solution and filesaver.js/html5 download in my project and this works without a problem, and without the need for any serverside code, or any plugin on the client. 100% HTML5/javascript.
There is no way generating a excel file on the client site with native GWT without adding a third party product. (see knarf answer below)
I personally prefer this solution:
open an new window on the client
use a url, that triggers a servlet on the server
let the server generate the excel file
save the newly generated file inside the webspace
return the url to the excel file to the client
This works for me.
I have an application where the server sends the data to a jsp file which gives the format and style and builds the xls file.
Using:
response.setContentType("application/vnd.ms-excel;");
response.setHeader("Content-Disposition","attachment; filename=\""+ name+ "\"");
then is offered to the user to open or save the file as usual.
The problem is that what I want is send that xls file to the server so it can be worked with and saved there.
Is there any way to do it?
Thanks for your help.
Why dont save the document when you are on the server side moment, before render into the view?. Then you can decide if the user want to remove just have to tell you to remove the xml that you just create.
If not the only way that I know is if you use JQuery use JQuery file upload http://hayageek.com/docs/jquery-upload-file.php
I'm looking for specific code on how to send a file from the server-side of a GWT application so that the client-side user can save it on his machine. Currently, the app allows the user to upload a file, reads it, and puts certain values from the file into editable text boxes. When the user hits the "save as" button, it collects that edited data, puts it back into the file string, and sends that string to the server, where I want it to be put into a file and pushed back to the user on the client side, so that they can save it to their machine. How exactly do I accomplish that?
Sorry if this seems like an obvious thing, but I'm relatively new to GWT and java in general. Thanks!
I think that you want the way for download a file using content-type from server using GWT.
The easiest way that I have found is create a iFrame :
import com.google.gwt.user.client.ui.NamedFramerdddccvc
...
NamedFrame iframe = new NamedFrame(frameName);
iframe.setVisible(false);
parent.addChild(iframe);
iframe.setUrl(url);
It's important that the url from the server return a page with content type "text/plain" or using the valid requested.
What you can do is create a servlet, that generates the text as content and set the matching mimetype for the content. In you app you can call this servlet via the by Fernando suggested IFrame method.
There are many suggestions here on Stackoverflow on how to do it. Search for [java] file download serlvet and you will find lots of examples/guidelines on how to do this.
I want to make a system where java client programs send images to a central server. The central server saves them and runs a website that uses these images.
How should I send the images and how should I receive them? Can I use the same webserver for receiving and displaying the website?
You need 3 things:
Upload client Need to know how to do multipart upload. See here
Upload Server There are a couple of ways. Apache Commons Upload is my pet.
Displaying File It's easy. If the files are uploaded somewhere under your web-app directory outside of WEB-INF directory. Just give the path like http://your/apps/base/url/folderName and the listing will come-up for download. There are ways to secure that. But I donot think you need to know that at this stage. By the way this may help.
And yes, same server can be used to upload and display (download) the images/files.
Hope this helps.
Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading operation of the file.
Thanks.
That's not possible. The client needs to send (upload) the file content along the request body to the server side whenever you want to have the file content at the server side.
If you'd expect that you can solve this by passing only the file path around and use the usual java.io.File stuff and so on, then you're on the wrong track. Imagine that I am the client and I have a c:/passwords.txt, how would you as being the server at the other end of the network ever get its content by java.io.File?
I don't thnik this is possible. Browsers do not allow any file transfer from the client to the server without user interaction.
Tough, if you do not stick to IceFaces, it may be possible to achieve this by writing an applet, wich is granted the necessary permissions.