I try to display a pdf file on my jsf2 application and the problem is in the path file.
My pdf file is inside a folder named FichesPratiques which is inside another folder named resources (folder resources is inside WebContent) and I use this to display it :
<p:media value="/resources/FichesPratiques/file.pdf" width="100%" height="300px">
but anything is displayed.
and more strange, when I use link below to download it, it doesn't work.
<h:outputLink value="/resources/FichesPratiques/file.pdf">click</h:outputLink> to download pdf instead.
Can someone help me ?
Look closer at the URL generated in the HTML output of those components (rightclick, View Source in webbrowser). In contrary to among others the <h:graphicImage value>, the <p:media value> and <h:outputLink value> do not prepend the web application context path in the URL. The leading / in the URL makes it relative to the domain root of the request URL (the one as you see in browser's address bar).
Imagine that the JSF page is been opened by
http://localhost:8080/somecontext/page.xhtml
Then those value="/resources/FichesPratiques/file.pdf" paths would expect the resource to be present in
http://localhost:8080/resources/FichesPratiques/file.pdf
However, you actually have it in
http://localhost:8080/somecontext/resources/FichesPratiques/file.pdf
You should either be using a valid URL relative to the current request URL,
<p:media value="resources/FichesPratiques/file.pdf" ... />
or explicitly specify the context path in the URL,
<p:media value="#{request.contextPath}/resources/FichesPratiques/file.pdf" ... />
Related
I am currently browsing the files (mostly images) on our server using HTTP, in the most primitive way (a very inefficient way).
To quickly glance a file, I need to click on and open it. Then exit, onto the next file. Very inefficient.
Is there a way that I can preview these files without opening them, just like what we do on our Mac/Windows system.
You could use Fancybox to get both a thumbnail view, and to open images without leaving the page. You can configure Apache to display your directory as a gallery, and add in thumbnails of your image into the DOM.
Try the instructions found here. The demo on that page doesn't seem to be working, but the instructions do work. The instructions there don't cover adding thumbnails, but in my abbreviated instructions below I added in a step to get them:
Download Fancybox
Create a fancybox directory at the root level of your site, and add the files from the Fancybox download.
Create a fancybox.html file in the fancybox directory and load the Fancybox library and set the config options. See the example here.
(My addition) Add a line to fancybox.html to insert a thumbnail into the Apache directory listing. Here's just a simple line you might add after line 26 in the linked example file:
$(this).html("<img src='"+ $(this).attr('href') +"' width='200'>" + title);
Create a .htaccess file in your image directory (and be sure .htaccess files are usable by Apache)
Add these lines to the .htaccess file:
Options +Indexes
ReadmeName /fancybox/fancybox.html
Navigate to your image directory
You can modify the Apache directory listing page to make it as pretty as you like. See this article on styling the directory listing. Probably any other gallery library you like could be used with a similar method, the important thing is that the ReadmeName option lets you inject javascript and css which you can use to manipulate the DOM.
I'm using Apache configured with AEM's dispatcher. On seemingly random occasions, the server returns a content type of 'httpd/unix-directory'. The user is then prompted to download the page in their browser. This response is then cached & subsequent requests to the home page present the user with a file download for index.html
How can I enforce text/html for all files with a .html extension?
This turned out to be a race condition.
Folder paths were being created with file extensions and cached. When that file was called (which was actually a parent folder to another file) it returned type as unix-directory.
The flow was something like this:
Request file: /path/to/filename.jpg/version/filename_120x120.jpg
Folder structure above was created, with filename_120x120.jpg returned & cached at Apache
Request file: /path/to/filename.jpg (which exists), returned 'file' to browser which was actually a file type.
Resolution:
Do not cache files where the parent folder structure contains a "."
I am having a html file which has anchor tag linking to the binary file in same ear. Problem is when I am clicking on anchor tag, the binary file is rendered instead of prompting for download or download. Doesnt have problem when using apache. Tried specifying mimetype in anchor tag by using attribute content-type="application/octet-stream" but didnt help.
Environment used is weblogic linux.
I think we need to configure mime-type at the server level rather than # anchor tags as server first would recognize the mime-type extension to service the download
Ref
https://blogs.oracle.com/brunoborges/entry/ohs_and_apk_files
I have a website on SiteFinity 4.4. I need to make a document available on a very specific URL, i.e.
http:www.example.com/reports/the-report.pdf
If I just create a directory in the root of the site it does not work (503 error). Also when I try to use the 302Redirect.xml file to redirect the URL to the PDF it does not work either (same error). The link has already been published and has to be exactly as specified. How do I solve this?
Any help would be greatly appreciated.
Sitefinity wouldn't block a folder. Adding a physical folder and dropping that report on the proper place should function, so it probably means you'll have to check your server configuration.
Anyway, the fastest way outside Sitefinity, would be to just create a IIS rewrite rule. Make the http:/www.example.com/reports/the-report.pdf the pattern and redirect them to the url of the document from the sitefinity library.
When you upload a document to the library in sitefinity it gives you an direct url, something like /docs/defaultlibrary/document. You can verify the url by going to content >> documents and files and chose Embed link to this file. That gives you a pop-up with the url.
If I want to display an image in my webpage and its src is a file outside context root.
At the IDE, the image is shown to be loaded.
But when I test the web page, nothing displayed.
How can I config weblogic server to allow the image to be displayed. If not is there anyway to run around this problem.
Thanks a lot.
You can use the Virtual Directory Mapping feature (that you declare in the weblogic.xml):
Using the virtual directory mapping
feature, you can create one directory
to serve static files such as images
for multiple Web Applications. For
example, you would create a mapping
similar to the folowing:
<virtual-directory-mapping>
<local-path>c:/usr/gifs</local-path>
<url-pattern>/images/*</url-pattern>
</virtual-directory-mapping>
A request to
http://localhost:7001/mywebapp/images/test.gif
will cause your WebLogic Server
implementation to look for the
requested image at:
c:/usr/gifs/images/*.
This directory must be located in the
relative uri, such as
"/images/test.gif".