Exporting JSP data into excel with image - image

In our project we are having the requirement to export the JSP page into excel.
We cannot use Apache POI or any other open source APIs.
I came across the below mentioned simple way of doing
<%
response.setHeader("Content-Disposition",
"attachment;filename=\"mult-table.xls\"");
%> <%# page
contentType="application/vnd.ms-excel"
%> <table><tr><td> using image src to
load images </td></tr></table>
The excel is generated but the image is not shown in the excel.
In our JSP pages we are having many images which should also get exported into excel along with other data.hanks
Please let me know how to do it.
Thanks
Ravi

I use the complete URL in HTML image code, because when you download the excel, it's a text xls file, with format HTML, and the images embeddable and the absolute path, intead it can solve the image source.
like this:
<%
// Java CODE
...
String url=request.getRequestURL().toString(); // URL base page
String imageUrl=url.substring(0,url.indexOf(request.getRequestURI()))+"/images/logo.gif"; // image absolute url
...
%>
...
<!-- HTML CODE -->
...
<img src="<%=imageUrl%>" width="198" height="36" /></th>
...

As far as I know you can not insert an image in xls file, when this html xls

Related

Send image link via Express and display with EJS

I am trying to make a quiz app and I am using the MEAN stack.
my server will send an object containing details pertaining to the questions - answers, image, question text. I wish to send a link to the ejs file which will then display the image referenced by that link.
I googled around to find some material on this issue but was unable to find any which address this topic.
I tried a few different method and the one below worked:
1) Add the link to the image in the object to be passed by the server
var objCard = {
QuestionText:"What is the indicated sign?",
ImageLink: "/assets/images/dummy.jpg"
}
2) Inside the ejs file use <%= %> from within the img tag
<img src="<%= objCard.ImageLink %>">

Read properties file without using Key

I have a property file without Key and only content and I want to display the content of property file in jsp Page after escaping html tags. How to do this?
property file:
Here is an example of content, messages. <p>
<b>approach<b> <br>
Find out more about our website
</p>
How can I display this in jsp Page using spring? Any help?
message.properties is typically used for internationalization. Usually properties file in general is used for small value(s) and plain text.
For your case, I'd just create a separate jsp file and include it in your jsp.
<%# include file="aboutus.jsp" %>

How to display uploaded images in pdf using wkhtmltopdf

I am using Carrierwave to upload images in rails4.
In the html view page the image is showing. But, when generating the pdf, from this view, the image is not showing.Instead , a blank box is showing.
From the view, while inspecting the path is showing as below:
<img alt="Small images" src=" http://127.0.0.1:3000/upload_
files/6/student/image/1/small_images.jpg">
The code i used is:
<%=image_tag Student.find(id).image_url(:small) %>
If the image is stored in app/assets/images, then the images will appear.But, i need to upload the image in this location only.
Can u pls help...
Thanks in advance.
I could do it with php Laravel this way >>
<img alt="Small images" src="{{base_path().'path/to'image.jpg'}}">
I have no experiences with Ruby , but try to find something similar.

correct use of getContextPath() on jsp

I have a problem using getContextPath() on jsp.
I want to add an image to the JSP, a logo.
I have read that is better to use getContextPath().
In my browser´s address bar I see de URL:
http://local.host:9080/Cold/start/Result.jsp
So I have assumed my getContextPath() is:
http://local.host:9080/Cold/
Next, I found the Result.jsp file at:
**C:\Users\myname\IBM\rationalsdp\workspace\Cold_WEB\WebContent\start**
So I have created the next path:
**C:\Users\myname\IBM\rationalsdp\workspace\Cold_WEB\WebContent\images**
And I have put the logo file there.
So, I have added next code:
<img src='<%=request.getContextPath()%>/images/SuperlineaPF.gif' border="0">
But, I still can not see the logo at the page on the browser.
What is wrong?
Thank you.
I find the following graphic from HttpServletRequest Path Decoding helpful:
Use the EL expression ${pageContext.request.contextPath}
You can do it following way in your JSP
<c:set var="context" value="${pageContext.request.contextPath}/images/SuperlineaPF.gif"/>
<img alt="image" src="${context }" border="0"/>
At the top of the page put an uri for JSTL as
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Note: You'll require JSTL library for it. This is for best practice.
Since your JSPs are placed under start in WebContent you can simply refer to your images following way.
<img alt="image" src="images/SuperlineaPF.gif"/>
You do not require page context for that.

Fancybox shows blob as string not image (Ruby issue?)

I am displaying an image obtained from a database (stored as a long blob) in an img tag using the following method:
<img src="http://localhost:3000/show_image/265" />
The show_image function takes the image data from the database and renders it to the img tag using the send_data method.
When applying Fancybox onto the img tag, the data is displayed as BLOB data not the image..
Can anyone suggest a reason why? Or how I can solve this?
1) You have to apply fancyBox to the links (not the images) and the structure should be like this -
<a class="fancybox" href="big_image"><img src="small_image" /></a>
Example - http://jsfiddle.net/CYCeM/.
Well, it is actually possible to have only images, but then you have to use "data-fancybox-href" attribute to specify the large one - http://jsfiddle.net/6ZSWB/
2) Looks like the script would not be able to guess the content type from your hrefs. You have to either -
a) Create links having extension, e.g., "http://localhost:3000/show_image/265.jpg"
b) Set content type for fancybox, example - $('.fancybox').fancybox(type : 'image');
setting :type => "image/jpg" fixed the issue. I looked up the MIME content types and realised it was incorrectly written.

Resources