Filepath in jsp - html

Following are 2 (MSDS,Shell-CCL) folders in my application
MSDS-->WebContent-->cclFooter.jsp
Shell-CCL-->WebContent-->jsps-->cclTNCDetails.jsp
Now i am currently in cclFooter.jsp
I am trying to access cclTNCDetails.jsp in Shell-CCL folder
I have tried the following but none of them worked. Please explain how to do
<a herf="javascript:openLinkFooter('<%= contextpath1%>/../Shell-CCL/jsps/cclTNCDetails.jsp');">Exa</a>
where the context path takes me to root/MSDS folder.
Exa
But none of them helped. Pls tell me how to navigate to the given file

Try this:
<a herf="javascript:openLinkFooter('/Shell-CCL/WebContent/jsps/cclTNCDetails.jsp');">Exa</a>
I am not sure, what about the WebContent here.

Related

Download button not working, file not found

I'm trying to place a button that, when clicked, downloads the file aaa.txt.
I have that file on the same folder as my index.html.
I've tried this:
<a href="aaa.txt" download>aaa</a>
<a target="_blank" href="aaa.txt" download>aaa</a>
aaa
But none seem to work. When clicked, chrome downloads a aaa.htm and says "error:file not found"
Also, I'm on a private server, not just running the html file.
It is quite simple you just need to specify the route more accurately, by adding a forward slash "/" before aaa.txt
<a href="/aaa.txt" download>aaa</a>
for more info, you can refer w3school
It deepens from where you generate the link:
/ = root of the current app (/);
./ = current directory (/subfolder/subfolder/);
../ = parent of the current directory (/parentFolder/).
Means if you have only a index.html file in root then you need only /filename.ext. In your case:
aaa

Insert image into jsp page

I am sorry that I need to ask this but I already spent three days trying to do this. I am buidling Java Web application and I want to include image to JSP page. Project name is realestates and I have Files folder inside realestates folder.
My code is like this:
<img alt="govno" src="<%=request.getContextPath() + "/Files/kurac.jpg"%>" style="width: 400px; height: 300px;">
This is what gets generated on page after I open it in browser:
<img alt="govno" src="/realestates/Files/kurac.jpg" style="width: 400px; height: 300px;">
BUT, image is not dispayed, only alt "govno" is written. I have tried many many paths (relative, absolute, changed folder structure million times and whatever I could think of and find on internet but nothing helped). Who would say that such a thing will be so hard to do???
Folder structure on Tomcat server after deployment is:
webapps
- realestates
|- WEB-INF
|- Files
|- kurac.jpg
Here is a guy explaining it in less than a minute.
https://www.youtube.com/watch?v=dwjwSYOrnS8
So two things are required:
1.Add this line in some config xml file
<mvc:resources location="/files/" mapping="/files/**"></mvc:resources>
2.Include image into JSP page with this line
<img src='<c:url value="/files/korali.jpg"></c:url>' />
Looks like you got yourself (and everyone else) confused of where the image is.
From your question, it seems to be at webapps/realestates/Files/kurac.jpg, so this should work:
<img src="/realestates/Files/kurac.jpg">
From your first comment, it is at C:/Users/Lazar/Documents/workspace-sts-3.8.3.RELEASE/realestates/Files/kurac.jpg, so it will not be accessible via http://.
This won't work.
From your later comment, it is at /webapp/realestates/WEB-INF/Files/kurac.jpg.
Files inside WEB-INF are not publicly accessible.
This won't work either.
As a last resort, move the image file to webapps/ROOT directory.
Try http://localhost/kurac.jpg from your browser.
Replace localhost with your server hostname as necessary.
If it works, this will work as well:
<img src="/kurac.jpg">
If it doesn't, there is something wrong with your Tomcat configuration.
Try reinstalling.
I read your question and i have one solution for your problem you can use the INPUT STREAM for add an image in JSP page...
THIS IS JUST EXAMPLE...AND MAY HAVE ERROR BUT THIS IS THE WAY HOW TO INSERT IMAGE IN JSP...
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection =
DriverManager.getConnection(connectionURL, "user", "pass");
psmnt = connection.prepareStatement(
"insert into save_image(user, image) values(?,?)");
psmnt.setString(1, username);
ImageIO.write(image, "png", new File("C://image.png"));
File imageFile = new File("C://image.png");
FileInputStream fis = new FileInputStream(imageFile);
psmnt.setBinaryStream(2, (InputStream)fis, (fis.length()));
int s = psmnt.executeUpdate();
At first you must create image folder outside the WEB-INF directory and try that code <img src="${pageContext.request.contextPath}/Files/kurac.jpg"/>
Webpage never allows accessing any local files.
This means that if you write img src="c:\imagesfolder\abc.jpg" in the jsp file it will not work (it can work only in some editor but it will not work using a browser).
img src="http://localhost.8080/imageshow/sendimage/12/abc.jpg" width="100" height="100"

What is the correct way to express a path in order to get Pelican generated html to link to an image?

I'm just starting to create a blog with Pelican and wanted to link to an image. I did this by including the following line in my Markdown file:
<img src="./myImg1a.png" alt="./myImg.png" style="width: 750px; height: 800px;"/>
This line was successfully reproduced in the html file, which Pelican placed in the output directory (i.e. /myBlog/output). I placed the png files in the output directory (i.e. the same directory as the html files and got the following error:
WARNING:root:Unable to find file /category/myImg1a.png/index.html or variations.
where /category refers to myBlog/output/category. When I, instead, used the following html code:
<img src="/myImg1a.png" alt="/myImg.png" style="width: 750px; height: 800px;"/>
everything worked fine. I don't understand why this should be:
If the image file is in the same directory as the html file, shouldn't "./myImg1.png" be correct and "/myImg.png" be incorrect?
Why was the folder /category/myImg1a.png/index.html being sought at all?
First of all, by design, you should not change the contents of the output directly/manually.
You should put all your static contents in separate directory which is usually named as images or paths. And, then configure the path(s) in pelicanconf.py as:
# ...
PATH = 'content'
STATIC_PATHS = ['images', 'files'] # add any no. of locations
# ...
In that case, when Pelican is building actual page, it will look for any referenced static file in ./content/images and ./content/files locations. If cannot find there, it will emit the error message.
Now, answering to your trouble ...
By,
... src="./myImg1a.png" ...
Pelican look for this myImg1a.png file in your myBlog/content/ folder as you are mentioning ./ which is the root folder for Pelican is working on.
But, when you are referring it as
... src="/myImg1a.png" ...
Pelican eventually finds it in the html file's directory. By getting / as location, Pelican is looking for it in the same directory of your myblog/my-blog-post/index.html which is myblog/my-blog-post/.
Hence, working. But not in the ideal way.
For a deeper understanding, please take a look into Pelican's documentation on this matter.
Why was the folder /category/myImg1a.png/index.html being sought at all?
Pelican, here, just trying to be smart.

can't locate css files in paths

My directory structure is something like this
APPLICATION
|
+-[code]
+-[config]
+-[database]
+-[includes]
+-[src]
+-.htaccess
+-composer.json
Pretty self explanatory. The .htaccess guides requests to src/index.php, the code is the middle tier logic, the database is the DAL and the config is configuration INI filies.
The problem I have is that my header file... I have a header.php file in [includes] that holds all of my css directives (html5reset, global.css, etc) but for some reason I can't access them. The fact that I can access the header file makes me think I should be able to access the css files (which live in [includes]) but they are not loading.
The odd thing is, in firebug, it looks like the actual html page is loading in the place where the css is loading.
this is my call from /includes/header.php
<link href="/includes/css/html5reset.css" type="text/css">
Confusing question, I apologize. Any advise would be appreciated.
in your config.php file you can define a URL (baseurl)
define('URL', 'http://localhost/myproject/');
then you could use this defined variable like so...
<link href="<?php echo URL ?>includes/css/html5reset.css" type="text/css">

Store Images in App_Data and address them absolute make errors

I've generated an image tag like below:
<td>
<img src='#item.SourceAddress' alt="#item.Description"/>
</td>
and the result is somrthing like this:
<td>
<img src='C:\Users\leo\Workspace\Team Foundation Server\Sources\HRS\HRS\App_Data\user\Photos\test.jpg' alt="desc"/>
</td>
The problem is I only see blank space and no image at all(in firefox I only see alt text). the path is correct. I copied the img tag itself into another html file and I see the image crystal clear.
somrthing that might help: I opened the source with firefox and when I clicked on source of image I got following error:
Firefox doesn't know how to open this address, because the protocol
(c) isn't associated with any program.
and sorry for terrible english by the way.
Edit: I Edited the title. It is make more sence now!
This may be due to you providing a local path name (i.e. a directory in C:) rather than a relative path via Razr. If you start debug in Firefox then the console output sometimes eludes to this.
You could try something similar to:
<img src="#Url.Content(Item.SourceAddress)" alt="desc"/>
And check that SourceAddress is in the format of:
~/MyImages/Photos/test.jpg
Also worth checking all the obvious things like double quotes over single quotes etc.
Finally found out what is the problem!
First of all I used App_Data Folder to store files. this folder is special purpose and is used to store some special database files and IIS wont give direct access to this folder. and I had to make another folder like Image and store files there.
Second problem is I gave the path directly from Root (C:\...). The Web Browser doesen't have access to the Server File System Directly (Due to some security reasons). Because of this I had to gave the path relative address. The absolut path should be used by Server Code only and not in html source.
I managed to convert absolute path to relative like below:
`public static class HttpServerUtilityExtensions
{
public static string RelativePath( this HttpServerUtilityBase utility, string path, HttpRequestBase context )
{
return path.Replace( context.ServerVariables[ "APPL_PHYSICAL_PATH" ], "/" ).Replace( #"\", "/" );
}
}`
and:
``