In my web application, I want to upload images and hence present them using p:graphicImage. I store the uploaded images outside the web app – in particular at E:\webapp\upload. Note that my tomcat server is installed on E: volume. I have created an ImageServlet to read the images as described in http://balusc.blogspot.com/2007/04/imageservlet.html.
I added the following configuration to my web.xml file:
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>utilities.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/upload/*</url-pattern>
</servlet-mapping>
I can access the images from the index.xhtml page using “upload/imageName.ext” eg:
<p:graphicImage value="upload/flag.gif" />
This jsf code is correctly converted into the following HTML code:
<img src=”http://localhost:8080/MyApp/upload/flag.gif?pfdrid_c=true”>
However, I want to be able to access images from pages which are contained into subfolders. Eg I have one page which is located at “admin” subfolder:
http://localhost:8080/MyApp/admin/language.xhtml
Inside that page, the same jsf code is converted into:
<img src=”http://localhost:8080/MyApp/admin/upload/flag.gif?pfdrid_c=true”>
which is wrong.
In other words, it looks for the images at “E:\webapp\admin\upload” directory which does not exist and hence nothing is displayed. I can clearly write the following code:
<p:graphicImage value="../upload/flag.gif" />
to make it work but I consider this as a bad practice because I will have to adopt the path each time I am in a different subfolder hierarchy (consider for example the problem of nested subfolders).
I am wondering if there is any way to just specify the relative path of the image eg “upload/flag.gif” regardless of subfolder hierarchy.
Thanks in advance!
Just let the path start with / to make it relative to the context root instead of the currently opened folder.
<p:graphicImage value="/upload/flag.gif" />
Related
my folder structure
enter image description here
And my code in the JSP page is
<script src='${pageContext.request.contextPath}/AppNameController.js'/>
I'm still getting 404 error
You have the prefix set to /WEB-INF/jsp but looking at your project structure your index.jsp is only within the /WEB-INF folder rather than inside the /WEB-INF/jsp folder.
Also change to:
${pageContext.request.contextPath}/resources/scripts/AppNameController.js
Can anybody tell me or give me a link to go to which can tell me how to implement and display images step by step (I'm only beginning) on a webpage from a spring project
I'm using IntelliJ
Thanks
What's the URL of the page? The one that appears in the location bar of your browser?
That is the URL to which relative locations are resolved in the HTML code. So, if the URL is http://localhost/MyApp/foo.html, and the URL of the CSS inside the HTML code is ../../css/style.css, the absolute URL where the browse will try to find the CSS will be http://localhost/MyApp/../../css/style.css, which doesn't make sense.
I prefer always using absolute paths for images and CSS files (and other resources). Using JSTL, that makes it like
<link href="<c:url value='/css/style.css'/>" ...
The <c:url> tag takes care of prepending the application context (/MyApp) to the path.
Note that relative paths inside CSS files are not resolved relative to the page URL, but relative to the location of the CSS file itself. So the path in your CSS file is correct.
I'm trying to make view page in CodeIgniter,So I create it and in Controller it loads complete.
but when I add images and jQuery to it,they will not be loaded.
I made sub folder in view folder by name of Files and add to view for e.g like that
img src="Files/01.jpg" but it will not be shown.
where should I place them?
I usually make a folder called files in the main directory (where system and application reside), and then link to them using base_url().
In your case, this would become
<img src="<?= base_url(); ?>/files/01.jpg" />
Hope that helps.
When your view loads, the file paths will be relative to the directory the CodeIgniter index.php file is located in. If this is also the root directory of your site, you can refer to it in this way: <img src="/Files/01.jpg" />
I have an MVC3 application with a couple of areas and a portable area as well (using MVCContrib)
Normally, I keep all my content files under ~/Content and my scripts under ~/Scripts.
However, I am building a fairly complex webclient to another service on my site and I want to organize those javascript and image files (LOTS of image files and resources) under the Area's folder structure, which looks something like this, under ~/Areas/WebClient
Content
css
fonts
images
js
Controllers
Models
Views
I have a resource aggregator controller (one of my portable areas) that is able to reach into the CSS/JS folders just fine to provide that content. However, the CSS files reference the images/fonts folders directly and all of those links show up broken. I have double and triple checked the paths and made sure everything was right but I still get 404 errors.
As far as I know MVC3 is supposed to ignore routing so long as there's a static file there. Also, as far as I know, only the App_* folders enjoy special protection. What am I missing? I'd rather not mix in my images and resources with my main application if I can at all avoid it.
As an example: http://localhost/Areas/WebClient/Content/images/knownimage.png will not work, but should, as it exists!
So after some sleep and, more importantly, stepping away from the problem I remembered that MVC does in fact offer you protection from people downloading views directly, which led me to remember the Web.config file required in the Areas folder. Sure enough, there's an httphandler that basically sends all requests to the FileNotFound handler.
All I had to do was drop a web.config file in the content folder I wanted to expose with the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler" />
</handlers>
</system.webServer>
</configuration>
Problem solved.
I can upload image to the directory but can not disply it on the page.
Tried using static html code and codeigniter img() function, both are not working.
Here is my code:
<image src="./applications/views/uploads/image.jpeg" />
and
$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');
the first code shows me broken image the second one shows Unable to load the requested file: taurus.jpeg
<image src="./applications/views/uploads/image.jpeg" />
By default, CodeIgniter denies access to the application folder which is why I suspect this isn't working.
$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');
I suspect this isn't working because your path is incorrect. The path is relative to the index.php file in the root of your application, not the file this code is in. Secondly, $this->load->file() sends to file contents to the browser so this wouldn't work anyway.
A solution would be to move your uploads folder to a web accessible location. For example, place the uploads folder into the root of your application - the same folder as your index.php file. Then you can display your image like this:
<image src="/uploads/image.jpeg" />
Just get rid of the dot (.) in the URL so your src url reads: "/applications/views/uploads/image.jpeg"