I have in my disposal a Spring MVC backed server, using AngularJS in client side to display dynamic content. Was researching possibility to get current content displayed in the browser and convert it to a word document.
I assume there's a way to do build word documents with Java, but to do so i'll have to send existing HTML to the server side - how would i do that? just send the document DOM object?
Suppose i'll be able to do so, what if i want to include 2 images? I do know its possible to send images as base64 string.
To conclude, my general approach would be to try and send all client side data to the server and use Java to generate word document.
I have found docx4j so this approach seems possible.
Is that the right way to go? Any thoughts would be appriciated.
On the server side, you can use a library like Apache POI for creating docx documents.
There are multiple ways to pass data from client to server:
Make an AJAX call
How to send FormData objects with Ajax-requests in jQuery?
Ajax Upload image
Submit a form from the client side to the server using POST. Using multi-part forms will allow you to send attachments to the server
See Handling HTML (multipart form-data) file uploads with Java
On the client side, there are some JS libraries available for creating docx documents:
https://github.com/evidenceprime/html-docx-js
Generate a Word document in JavaScript with Docx.js ?
Related
I have a simple html file that contain input and send button. is there a way to that, when the user submits, puts the data into a PDF file and sends/saves it on live server ? i use jsPDF library but it save pdf on client side.
Common approach is rather to send to the server request from html form than to form pdf on the client side.
If the server is java I would recommend iText library to create pdf.
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 am new to web programming. My web application can upload files (uploaded by drag and drop method in javascripts ) and i want to retrieve them in servlet using Json . servlet file only needs the contents of the text files to do the calculation.
Can any one suggest how to do this ?
softwares used - netbeans ,tomcat
Thank you.
I'm not quite sure if you mean rendering your files in servlets or actually downloading them from your browser. I'm going to assume you mean rendering them. If so, then what you have to do is set up a URI which is associated with the content you want to render. Let's say this is a simple "hello world" rendering in the browser. what you would do is set up a URI as such:
localhost:3000/helloWorld.html.jsp
What you do on your back end is then wait to receive a http GET request to "/helloWorld.html.jsp" page, and then have your router send over the correct page. Luckily, with tools such as tomcat, the routing from local host is straight forward enough, and as your comments mentioned this is simple enough to do with the ample resources on the web.
Also an important point, you don't need JSON when using servlets (if i understood your problem correctly). If you want to send over data in a JSON format, then all you would do is modify the above steps to listen for "/sendJSON.html.jsp" (this could be an empty jsp), and you send over JSON from your back end in your response.
This is going to be running on a server which will then send the xml request to another server (over which I have no control). I can't afford to write an xml to the hard drive for every request. So ideally I'd like to create an xml without creating the file.
This shows how to send an xml file (not an object) over https: http://pic.dhe.ibm.com/infocenter/iisinfsv/v9r1/index.jsp?topic=%2Fcom.ibm.swg.im.iis.ia.restapi.doc%2Ftopics%2Fr_restapi_sending_https_java.html I've got that part working, problem is even after changing the content type to xml I think it was simply sending the content of the xml as plain text which seems very inelegant.
I'd rather avoid third party jars as much as possible but I do have access to the apache.axiom and axis 2 library.
So long story short: how do I make an xml object and then send it via HTTPS to a third party web-service that is not using SOAP or REST.
The HTTP request is generally correct to send XML as text, with the correct content type.
If you have a DOM object of some sort, you would just serialize it to XML, as text, either on disk or in a buffer or a string, and then send that, as per the link, to the other server. The other server will parse the XML string and get whatever form of object it wants.
I am looking for a solution to upload a file from a client to a server connected through a web service.
The client is written in c# and the web Service in java.
The files can be rather large < 100MB.
What approach would you suggest is best ?
Base64 encode the file and send it as an attachment. If you need to make sure the contents of the attachment do not get changed en route, use MTOM. Otherwise, use DIME.
Agree an encoding on both client and server then serialize the file using that encoding, wrap it in CDATA tags and assign the value to a text node in your SOAP request on the client.
Read the data between the CDATA tags on the server, deserialize it using the agreed encoding and you'll have the byte stream to use as need be.
It's probably a good idea for the encoding to involve some sort of compression if the files are large, although be wary of interop issues if the client is .NET and the server Java.
For the server side, you should have a look at Commons File Upload