I have tried the image uploading code in java.Images are upload in -
D:\bridge\Project\.metadata\.plugins\ org.eclipse.wst.server.core\tmp0\wtpwebapps\bridghc\Example\image-folder\2nd page.jpg this directory.
This fully path is also inserted in database.When i fetch the path from database i get the same result but when i write
<img id="0" src="D:\bridge\Project\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bridghc\Example\image-folder\2nd page.jpg" name="txtrepimg0">.
In the web page i am not able to fetch the image.I got failed to load url.
Please help.
The src attribute in the img tag only accepts web addresses as targets, not local directories. So the path should look something like http://mysite/images/myimage.jpg
You should store relative path into database not Actual path of file. you should only store
file name, as your folder is fixed to store images
2nd page.jpg
and use the following in img tag
<img id="0" src="application_name/your-relative-path-of-image-folder/2nd page.jpg
" name="txtrepimg0">
like
<img id="0" src="/bridghc/Example/image-folder/2nd page.jpg" name="txtrepimg0">
In your case application name is bridghc
Try change your upload path to something relative to your website location.
For example, if your webfiles(html, css, javascript, etc...) are in:
D:\bridge\Project\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bridghc\Example
add a folder like "image-folder" in a relative path like
D:\bridge\Project\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bridghc\Example\image-folder
save the relative path in database
\image-folder\image.png
and use it in your website
<img id="0" src="\image-folder\image.jpg" name="txtrepimg0">
Related
I am trying to add some images on README.file in my Spring Boot app as shown below:
### Diagram
<img src="D:\my-project\src\main\resources\images\entity-diagram.png" width="600"/>
However, I need to set this path as relative. But I could not set by directly referring resources folder in a smart way something e.g.:
<img src="~\images\entity-diagram.png" width="1000"/>
So, how can I give reference to the resources folder smartly?
if README.md is parallel to pom.xml (AKA "basedir"):
<img src="./src/main/resources/images/entity-diagram.png" width="600"/>
I want my image show up in receipt_failure.html via such thymeleaf expression :
<img th:src="#{/src/main/resources/images/icons-alert-circle.png}" />
Image itself has settled in such SpringMVC folder structure:
I do not get where issue comes from because seems like I keep path structure but I am getting such error on my local environment
I moved /images folder into /static folder then fix html like this:
<img th:src="#{/images/icons-alert-circle.png}" />
and issue has been fixed
I have created a simple jsp page in the spring mvc project. But i am unable to load the images from the image folder. I tried with Real path and Context path still I am unable to load the images in to the jsp file.
Real path:
<%
String realPath = application.getRealPath("/");
%>
<img src="<%=realPath%>images\logo.png" alt="student" title="student">
Context Path:
<%
String contextPath = request.getContextPath();
%>
<img src="<%=realPath%>images\logo.png" alt="student" title="student">
My project folder struture looks like
Did I miss something? Do I need to make any configurations in the web.xml?
Any suggestions?
You must configure your static resources like images, js and css files like that:
<mvc:resources mapping="/images/**" location="/images/"/>
In the above example, any requests from this url pattern /images/**, Spring will look for the resources from the /images folder.
You cannot use real path, because the browser will not be on the same machine as the webapp!!
You cannot use \, because URLs must use /.
Don't use Java code in JSP, especially when EL variables are there to be used.
You are missing a /. Quoting javadoc of getContextPath():
The path starts with a "/" character but does not end with a "/" character.
This is how to do it:
<img src="${pageContext.request.contextPath}/images/logo.png" alt="student" title="student">
I'm working on a web project using java/ jsp/ servlets/ html/ css in eclipse tomcat, where everything is in the WebContent folder.
In my jsp files... When I try to include other jsp files (using a link like "/fileName.jsp" in jsp include directive) I can do that successfully.
But When I try to include image files (using a link like "/fileName.jpg" in the <img src=""> tag) nothing happens.
Nothing happens because instead of looking in the WebContent folder for image file it looks in the tomcat home directory, i.e.
Instead of looking at "http ://localhost:port/projectName/..." it looks at "http: //localhost:port/..."
Why does it look at the wrong location only with <img src=""> tags but not in <%# /> tag.
A workaround for this is that I start giving absolute paths "/projectName/..." However doing this means I'm hardcoding project name everywhere. This is what I do not want.
Don't include binary content in an ascii output. Why not just use the img tag? If you need to do something to produce a jpeg, I would use a Servlet.
Because the jsp-Links in the website are getting processed and the image links not. Either change the image path or develop an filter that changes the images'links.
Yes Templar, that could have been a way to solve my problem.
However, I simply changed the Context Root of my project from "Project Name" to "/" in Eclipse. This solved my problem.
i am saving my images through java coding in a folder called "files".
and in my jsp page i am trying to display that image using
<img alt="" src="${pageContext.request.contextPath}/files/IMG168.jpg"> But the image is not displaying! What could be the reason.
Please see the below images and suggest me solution for my problem.
You should put the files folder in WebContent directory.
Web pages contains as below
Web pages
|______page1.jsp
|______index.jsp
|______page2.jsp
|______WEB-INF
|______images
|______css
|
Just try this and see
<img alt="" src="../../files/IMG168.jpg">
Updated,
I think you have to get physical location of files folder and put it in to src. Example if your files folder in C:\visionbook\files your
src="C:\visionbook\files\IMG168.jpg"