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"/>
Related
I am making a Qute Template and there is a logo image in the header that I need to have loaded.
The path that is being used within the html is this:
<img style="width: 10cm;" src="logo.png" alt="Logo Flower">
The image path from the main folder is resources/META-INF/resources/logo.png.Click here to see the folders.
When the template is rendered, the image is not loaded and shows an error on the GET request:
GET http://localhost:8080/api/user/logo.png 404 (Not Found)
Does anyone have an answer on how to put the path of static files correctly in Qute templates?
It seems your HTTP path is wrong. It should look like this:
GET http://localhost:8080/logo.png
Try to inspect (CTRL + I) your page go to sources and try to figure out where is the problem...
Here is example on my project: META-INF/resources/logo.png
resources path
, and here is my img tag <img id="logo" src="logo.png" alt="Logo">
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 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
i have a struts2 action which has a variable for an image which i want to display in a jsp page. when i display the value of the variable using the following:
<s:property value="variableName" />
i get the absolute path of the image file.
but when i try the following:
<img src='<s:property value="variableName" />' />
i get a blank there. i have even tried the following:
<img src="${variableName}" />
EDIT: i have done some thinking. the path of the image which is set is in temp folder of tomcat. is it because of that that i am unable to access it?
to no effect. what may be the issue in this?
Always keep in mind when doing web development what you have in server context and what travels to the client browser. If you do what you are suggesting, you will render and send to the client something like this:
<img src="c:\my_local_directory\some_image.jpg"></img>
Which means nothing to the client browser, which is surely executing in some other machine.
You should store your images somewhere where your application server can show them, and give always paths that are relative to your web application. For example, if you have stored some_image.jpg straight in your my-app.war file, something like:
<img src="/my-app/some_image.jpg"></img>
will always work. If you need to refine that image (imagine you need to put a watermark on it before) or need to recover its contents from somewhere (a BLOB in a database or something like that), you will need an entire new action in order to do it, for example:
<img src="/my-app/ImageAction.action?image=some_image"></img>
The src of the img tag must contain an absolute path, then only it can point to the image file from the client machine.
If the variableName contains an absolute path like this
http://localhost/images/pics/icon.gif
The img will finds the image from the server. Thus available always an hence you can use this.
<img src="${variableName}"/>
If the variableName is a relative path ie; something that's recognisable for the server.
/images/pics/icon.gif
The above path will be identified by the server but it wont be identified from the remote machine. In that case you need to have this
<img src="<c:url value=variableName/>" />
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.