I wanted to know if there is a way in which I can pass an HTML table from my JSP page using the Java request object.
More precisely, this is what my table looks like..
table id="tableid"
thead
tr
th...column1 header.../td
th...column2 header.../td
/tr
/thead
tbody
tr
td...column1 data../td
td..column2 data../td
/tr
/tbody
/table
I've a method in my Java code getExcelVersion(), for which I wanted to pass the above table as an argument.
I actually wanted to pass data from the table(column1 data, column2 data) as an List, ArrayList or anything data type, and not the actual HTML. What I'm basically trying to achieve is something as follows:
I've an HTML table, that I need to export to excel on a button click. For this purpose, I'm using libraries from Apache-POI, and the foll. code block.
HSSFWorkbook workbook = getExcelVersion();
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition", "attachment; filename=\"contacts.xls\""); workbook.write(resp.getOutputStream());
resp.flushBuffer();
Now, I wanted to know how would I pass table data(column1 data, column2 data) to my getExcelVersion() method.
Thanks,
Pritish.
Apache POI doesn't take a HTML table as input, but just fullworthy Java objects. Just reload the same data in the servlet as you loaded for the initial display in JSP and then feed it to Apache POI instead of forwarding to JSP. If you want to avoid reloading the same data, then you can consider to store it in the session scope, but this has a negative impact on server memory usage and client experience.
At least, I'm assuming that your JSP/Servlet/database code is well written, else it's going to be a lot of refactoring/rewriting work.
Related questions:
How to avoid Java code in JSP files?
Hidden features of JSP/Servlet
Export to Excel (CSV) using JSP/Servlet
Related
In my anylogic model my agents receive their parameters from a database table, which is based on an Excel file. In the Excel file, each cell has its own code stored, so each time I open the file, the cell values change.
I would like to have that with each automatic run of my model the Excel file is read in again as the database table (i.e. the parameter values of the agents change).
In the "Parameter Variation Experiment" I entered this code under "after iteration":
String tempString = excelFile_DatabasisLinks.getCellStringValue(1, rowCounter, 1);
ModelDatabase modelDB = getEngine().getModelDatabase();
Database myNewFile = new Database(this, "rohdaten2", tempString);
modelDB.importFromExternalDB(myNewFile.getConnection(), "Rohdaten", "rohdaten", true, false);
rowCounter += 1;
I have the code form this anylogic help page. Using a variable to be able to change the path of the file (i.e. the file) seems to work (anylogic doesn't throw an error).
In the currently used dummy model, the agents receive their parameters at the source.
At the sink, the parameter values are written via collections into another excel (results) file.
I put obvious pattern into my data files, to see if the data changes, but I always receive the same excel file in my results file.
I read that anylogic copies the excel tables to its temporary files to make simulation runs faster. I hoped the code above would be a workaround, but it is not.
I'm grateful for any suggestions how to make this work!
I could not find out what is wrong with the above code or how to get it work.
However, I found a workaround using the "excelFile "-Block.
In the main agent (the agent where all other agents live) in the agent actions in "on startup":
excelFile.readFile();
ensures that the excel file is updated before each run. The parameters are added via
agent.set_<parametername>(excelFile.getCellBooleanValue( sheet number, row number, column number)
"on exit" in the source.
I hope this helps everyone with a similar problem.
I have a JSON that looks more or less like this:
{"id":"id","date":"date","csvdata":"csvdata".....}
where csvdata property is a big amount of data in JSON format too.
I was trying to POST this JSON using AJAX in Play! Framework 1.4.x so I sended just like that, but when I receive the data in the server side, the csvdata looks like [object Object] and stores it in my db.
My first thought to solve this was to send the csvdata json in string format to store it like a longtext, but when I try to do this, my request fails with the following error:
413 (Request Entity Too Large)
And Play's console show me this message:
Number of request parameters 3623 is higher than maximum of 1000, aborting. Can be configured using 'http.maxParams'
I also tried to add http.maxParams=5000 in application.conf but the only result is that Play's console says nothing and in my database this field is stored as null.
Can anyone help me, or maybe suggest another solution to my problem?
Thanks you so much in advance.
Is it possible that you sent "csvdata" as an array, not a string? Each element in the array would be a separate parameter. I have sent 100KB strings using AJAX and not run into the http.maxParams limit. You can check the contents of the request body using your browser's developer tools.
If your csvdata originates as a file on the client's machine, then the easiest way to send it is as a File. Your controller action would look like:
public static void upload(String id, Date date, File csv) {
...
}
When Play! binds a parameter to the File type, it writes the contents of the parameter to a temporary file which you can read in. (This avoids running out of memory if a large file is uploaded.) The File parameter type was designed for a normal form submit, but I have used it in AJAX when the browser supported some HTML5 features (File API and Form Data).
I'm attempting to render a notes document to RTF, then DXL using the Java API. Once I have the DXL, I'm converting it to HTML with an XSL stylesheet. My goal is to produce an HTML document that displays as close as possible to the document rendering in the notes client.
However, computed fields are missing from the rendered RTF and DXL.
Here is the code used to generate the DXL:
private String renderDocumentToDxl(lotus.domino.Document lotusDocument)
throws Exception {
Database db = getDatabase();
lotus.domino.Document tmp = db.createDocument();
RichTextItem rti = tmp.createRichTextItem("Body");
lotusDocument.computeWithForm(true, false);
lotusDocument.save();
lotusDocument.renderToRTItem(rti);
DxlExporter dxlExporter = getSession().createDxlExporter();
dxlExporter.setOutputDOCTYPE(false);
dxlExporter.setConvertNotesBitmapsToGIF(true);
return dxlExporter.exportDxl(tmp);
}
Fields added to the document by the call to computeWithForm are not present in the generated DXL.
Is there any way to get the computed fields into the generated DXL with the Java API? Or is there a better way to generate an HTML representation of a notes document using the domino Java API?
I'm not quite clear on your objective. There are two possibilities:
1) You want the items from lotusDocument to exist in tmp, and to be exported as actual tag data in the DXL. Your code does not do this.
2) You want the values of the non-hidden Items from lotusDocument to exist as text within the rich text Body item in tmp, and you want those values to be included within the DXL that is exported from tmp - as text within the tag for the Body item. This should be what your code is doing.
If you expected the former, then that's not what renderToRTItem does. What it does is the latter. I.e., it gives you a snapshot of the values of the items in lotusDocument - but if and only if they would be displayed to a user who opens the document. You do not get the items themselves, and they won't appear separately in the DXL. If that's all you expected, and it's not happening, then there's something else going wrong and you haven't given enough infornmation here to figure it out.
If you wanted the former, i.e., the actual items from lotusDocument to exist as separate tag elements within the DXL exported from tmp, then you should be using
lotusDocument.copyAllItems(tmp,true);,
or sequences of
Item tmpItem = lotusDocument.getFirstItem(itemName);
tmp.copyItem(tmpItem,"");
You can get the HTML representation of a RichText field with the URL
http://server/db.nsf/view/docunid/RichTextFieldname?OpenField
So, save your tmp document, get the docunid and read the result via http from URL
http://server/db.nsf/0/tmpdocunid/Body?OpenField
You don't need to call lotusDocument.computeWithForm as lotusDocument.renderToRTItem does execute form's input translation and validation formulas already.
Be aware that for both methods form's LotusScript code won't be executed - just in case your fields gets calculated this way.
In case you can use XPages this would be an alternative: http://linqed.eu/2014/07/11/getting-html-from-any-richtext-item/
I have a JSP in which I want to:
make an HTTP request;
get back the XML response;
transform the response using XSL; and
export the transformed data to excel.
But i do not get the entire data in a single HTTP call. Also I have to use two stylesheets for exporting to Excel. The first is for the first page of records, and the other is for all the other pages.
How can one do this in Java?
Thanks
Or use Apache POI, its a powerful API to read and create MS Office documents in Java.
Could you parse the XML into Java objects, then when you have the complete object list simply write the Excel file using JExcelAPI? I've used this for Excel files and it's very simple & useful.
I'm currently writing some MATLAB code to interact with my company's internal reports database. So far I can access the HTML abstract page using code which looks like this:
import com.mathworks.mde.desk.*;
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.setCurrentLocation(ReportURL(8:end));
pause(1);
s={};
while isempty(s)
s=char(wb.getHtmlText);
pause(.1);
end
desk=MLDesktop.getInstance;
desk.removeClient(wb);
I can extract out various bits of information from the HTML text which ends up in the variable s, however the PDF of the report is accessed via what I believe is a JavaScript command (onClick="gotoFulltext('','[Report Number]')").
Any ideas as to how I execute this JavaScript command and get the contents of the PDF file into a MATLAB variable?
(MATLAB sits on top of Java, so I believe a Java solution would work...)
I think you should take a look at the JavaScript that is being called and see what the final request to the webserver looks like.
You can do this quite easily in Firefox using the FireBug plugin.
https://addons.mozilla.org/en-US/firefox/addon/1843
Once you have found the real server request then you can just request this URL or post to this URL instead of trying to run the JavaScript.
Once you have gotten the correct URL (a la the answer from pjp), your next problem is to "get the contents of the PDF file into a MATLAB variable". Whether or not this is possible may depend on what you mean by "contents"...
If you want to get the raw data in the PDF file, I don't think there is a way currently to do this in MATLAB. The URLREAD function was the first thing I thought of to read content from a URL into a string, but it has this note in the documentation:
s = urlread('url') reads the content
at a URL into the string s. If the
server returns binary data, s will
be unreadable.
Indeed, if you try to read a PDF as in the following example, s contains some text intermingled with mostly garbage:
s = urlread('http://samplepdf.com/sample.pdf');
If you want to get the text from the PDF file, you have some options. First, you can use URLWRITE to save the contents of the URL to a file:
urlwrite('http://samplepdf.com/sample.pdf','temp.pdf');
Then you should be able to use one of two submissions on The MathWorks File Exchange to extract the text from the PDF:
Extract text from a PDF document by Dimitri Shvorob
PDF Reader by Tom Gaudette
If you simply want to view the PDF, you can just open it in Adobe Acrobat with the OPEN function:
open('temp.pdf');
wb=com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
wb.executeScript('javascript:alert(''Some code from a link'')');
desk=com.mathworks.mde.desk.MLDesktop.getInstance;
desk.removeClient(wb);