I have uploaded a PDF on server by servlet , get that file on client side. Now I want to set the file to the src of Iframe. I have seen the examples but they are setting the src like src='http://www.tutorialspoint.com/java/java_tutorial.pdf?file=http://www.tutorialspoint.com/java/java_tutorial.pdf but I have the file with name like "file12314232343244"
I am setting the src like this
HTML pdf = new HTML("<iframe position='absolute'src='http://www.tutorialspoint.com/java/java_tutorial.pdf?file=http://www.tutorialspoint.com/java/java_tutorial.pdf' />");
what should I do for that ?
Use the type parameter:
type="application/pdf"
as shown https://stackoverflow.com/a/42908837/2979092
Related
In order to include css in the velocity I'm using the syntax as below in my html file.
#include("css/temp_css.css")
What would be the syntax to include the images in html file using velocity?
To embedded image You don't need include the file . You can directly have img tag in vm file itself.
And for above code you can pass some url from the java object.
Map velocityObj = new HashMap();
velocityObj.put("imageUrl", "Your full Url ");
I'm trying to open a PDF file by requesting it from Rest endpoint. But in this case, the file is getting downloaded. I tried opening it in another window. There also it just shows new window and downloads it there.
I used Chrome. So in Chrome by default it downloads the file while in Firefox it shows the dialog box whether to open it or save it. I don't want that dialog box. But want to display the file in new window with all the features like download, print, etc which a normal pdf viewer will show.
Is there some way through which I can avoid downloading of the file by default and just display that file in another window? Content-Disposition is attachment; filename="abc.pdf" when I see the properties of the URL. Also, its content-type is application/pdf;charset=utf-8.
<a target="_blank" data-content-type="application/pdf" onclick="open(this.href, this.target, 'fullscreen=yes'); return false;" data-type="downloadTenPointDocument" href="<c:out value="${resultItem.offer.programInfoUrl}"/>">View 10-point</a>
I changed the properties of pdf file from attachment to inline and set it in response:
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "inline; filename=" + fileName + ".pdf");
I am requesting the pdf file from server and then reading it and setting it in response, changing the properties of it in response, so that its default behavior of getting downloaded is overwritten.
Thank you everyone. The answer to change the property of pdf file was right.
You won't be able to do it directly from REST endpoint.
Use target="_blank" in anchor element on your page.
go
You should try to erase attachment; property from content disposition header.
i did like that and it worked: (it wont start to download, and it will open in a new tab (target _blank) if same tab, thenit is (target _self)
show pdf in a new tab
Let's say i have created the file
String path = application.getRealPath("userSearchFolder");
String name = path + "/" + (String) session.getAttribute("username") + ".xml";
File file = new File(name);
And later I want to make it available as a link, for example
<a href"<%=file.toURI()%>">File</a>
What happens is I get the directory path not url path ->
file:/D:/Documents/NetBeansProjects/2012/GATE_Project/build/web/userSearchFolder/mjoraid.txt.xml
And when it reaches Firefox, I hover over the link and what i see is
file:///D:/Documents/NetBeansProjects/2012/GATE_Project/build/web/userSearchFolder/mjoraid.xml
When I right click and choose Copy link Location and paste it in URL the xml file opens, but when I click the link, nothing happens.
How could I get a link like this
http://localhost:8080/GATE_Project/somepage/somepage/mjoraid.xml
The getRealPath will give a File system path (hence "real"), as opposed to web app path. So you cannot make it a href.
The following should suffice.
<a href="/userSearchFolder/${userName}.xml">
(Of course you are risking data mining for such public accessible XML files.)
You could use a servlet to serve the file.
This tutorial shows how to serve a pdf file(!)
the theory is the same:
you load the file in the servlet
Set any required headers
write the data to the response
The ContentType should probably be "application/xml".
Ok, i did it manually, similar to how i used to do it in php, create a variable that contains the website main directory.
String searchFolderURL = "http://localhost:8080/GATE_Project/userSearchFolder/";
and then
<a href="<%=searchFolderURL + file.getName()%>" target="_blank" >See original txt File </a>
Thanks btw.
I want to use the following js function to insert an image on a webpage, but I am not referencing the icon file correctly.
function insertWarningIcon(value){
return "<img src='/icons/Warning-icon.png' width='25%' height='25%' />";
}
The image is contained in a java package 'icons.' The file's path is:
C:\Users\XXXX\Documents\NetBeansProjects\distributedTaskMonitor\src\java\icons\Warning-icon.png
The html file's path is:
C:\Users\XXXX\Documents\NetBeansProjects\distributedTaskMonitor\web\gridMain.html
you can't point to src package from web pages, you have to put them into "WebContents" folder (it's outside of src folder)
eg.
WebContents/images/icons/icon1.png
is
<img src="images/icons/icon1.png"/>
I am developing a web page in which I have to upload multiple files on
a single browse.
I am using html <input id="filelist" type="file" multiple=multiple>
This enables the multiple file selection and also retrieves the
full file path of all the selected file, which shows in file
upload text area.
<script language="JavaScript">
<!--
function showname(){
var filepath = document.form1.filelist.value ;
alert(filepath); //this shows only first filename among selected file
}
-->
</script>
But the problem is when I get the value of input, it returns only the first file
name among selected files.
Now how can I get the file paths which is shown in file upload text area.
Thanks!
This is browser specific. So you might be running this in a browser that doesn't support this. For example Firefox does. Here's an example of how to use this feature:
http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/
I would consider using http://www.uploadify.com/about/ or http://www.fyneworks.com/jquery/multiple-file-upload/. They should help you out, and also add some cool features to your file upload form.
File paths are deliberately hidden from the page for security purposes. To look at the local filesystem you need to use Java, Active-x (meh), or Flash.