HTML Links are adding an extra path in the href - html

I am currently designing a small website using JSP / Servlets. Tomcat is very picky about my routes.
My application can be entered throught the path /Final (on a localhost I have http://localhost:8088/Final).
My main JSP page is at http://localhost:8088/index.jsp. On that page, I have a navbar with several links. On one of those links, the "Home" link, I have the href set to /Final/index.jsp. When I hover over the link, it shows the links path as http://localhost:8088/Final/Final/index.jsp.
At first, I said ok, lets just change the href to index.jsp, but when I do that, the link now points to http://localhost:8088/index.jsp which will not satisfy the server. Why are links behaving like this? How can I get it to point to http://localhost:8088/Final/index.jsp without fully qualifying it?

You could use a relative path such as pointing it directly to it's location. I'm not sure if this would work, but try putting /index.jsp as the href in your link. This way it's going from your current folder "Final" and going one level down to index.jsp.

Apparently, adding the . before the path as in ./index.jsp works just fine.

Also, you can try to escape your file and specify it again, it worked for me.
For example: ../jsp/index.html

Related

html image will work on one page but not another

Im using Atom to do some homework, I am a beginner at html this is my first assignment and I am trying to make my first page, however I am having problems getting my images to show up. I got them to show up on a previous page and now I have moved on to a different page and tried to use the same and it won't show up, I even tested it on another page and it works on there, I don't understand what im missing can someone please steer me in the right direction.
img tags have a property named src. this prop should fill with path of your image. if you use absolute path, it should started with '/'.
imagine that you have a directory named 'public' and a file named 'image.png' in that directory. you can use img tag like this:
<img src="/public/image.png"/>
keep in mind that start slash is referred to the base directory of your project.
to check the path, you can inspect in your html file. open your html file in your browser. right click and select inspect (or you can press F12 and go to inspector tab if you are using firefox or chrome).
find the <img {...}/> element and check it's src prop and path url. keep in mind that the path should open the image. if that's not happening, there is a problem with your path.

Internal Links in HTML

I have a lot of internal links I want to use for the first website I'm building. It works great when I run it locally but none of the internal links work when on the actual site. For example, here is one internal link I'm using.
Read More
I understand why this doesn't work, but what link can I put there if one doesn't exist yet? I guess how do I create sub pages for my website?
Thanks in advance!
Here's simple example, You cannot use absolute path on server, but relative using .. (back to parent directory) or . (current) to link to file that you need.
If you don't have a page yet, leave it #
like Click here
You can put relative links in each page. Lets assume your site hierarchy is such:
index.html
category-a.html
category-a/page1.html
category-a/page2.html
category-b.html
category-b/page1.html
category-b/page2.html
The link from index.html to category-a.html would be:
category a
The link from category-a.html to category-a/page1.html would be:
page 1 of category a
The link from category-a/page1.html to index.html would be:
Home

Links in html confused

I am making a web portal but I am a little confused with the use of the links. The problems is.
My application is in http://localhost/applicacion/default.aspx (application is the application directory)
If i put a link Link it takes me to
http://localhost/Admin/defaultadmin.aspx instead of take me to ---> http://localhost/applicacion/Admin/defaultadmin.aspx
Then i try with Link it takes me to
http://localhost/applicacion/Admin/defaultadmin.aspx but if i am in another part of the site like http://localhost/applicacion/sales/defaultsales.aspx it takes me to
http://localhost/applicacion/sales/Admin/defaultadmin.aspx witchs is wrong !!
what's the rigth combination so the link takes me always to the same point, having in mind tha the application directory can change in the installation so that part has to be dynamic, I means I can not put in the link Link because the user may install it in another web site.
Thanks !!
You are stating to goto the parent directory by ../:
Link
If you want to go to a sub-directory then omit the ../ and just use the name of the sub-directory followed by the desired page:
Link

How to make a picture link with HTML?

I have made a picture link with this code snip:
<a href='feed.php'><img src="C:\xampp\htdocs\Project\Icons\Feed.png"/></a>
But no picture appears on my page, why?
(I'm currently only using my page locally!)
It's because you (are trying to) use a local file reference.
Either use the relative path
or
<a href='feed.php'><img src="file:///C:/xampp/htdocs/Project/Icons/Feed.png"/></a>
Please be aware that if you plan to use this 'online' it will fail because of the LOCAL reference.
If you load the page through your webserver you should use:
<a href='feed.php'><img src="/Icons/Feed.png"/></a>
Or
<a href='feed.php'><img src="http://yoursite.local/Icons/Feed.png"/></a>
Or whatever the path to the image is.
I would prefer the relative path (the first) though which enables you to move your page to another domain without your links / images breaking.
You can't link local files from a remote web page. This is to prevent webpages from accessing files on the end-user's computer.
Change this: C:\xampp\htdocs\Project\Icons\Feed.png
To this: http://yourwebsitehere.com/Project/Icons/Feed.png
EDIT: Since you say its only used locally, then you need to use this instead:
file:///C:/xampp/htdocs/Project/Icons/Feed.png
Also, make sure the image is actually located where you think it is!
Try typing file:///C:/xampp/htdocs/Project/Icons/Feed.png into your browser's address bar and see what happens.

Base URL for HTML and CSS

I got a question and although I could find related information, I'm if it was exactly about what I'm wondering about.
The thing is, I got a site on http://localhost/site.
Now, when I create a link, let's say, <a href="/posts">, it links to http://localhost/posts instead of http://localhost/site/posts.
It works fine if I remove the slash (<a href="posts">), that would be the closest and maybe the easiest solution, but I'd like to know why the links ignore the folder where the file is at?
And I also would like to know if this can be fixed with .htaccess or something.
I've read that a link that begins with / makes it "absolute". So a link beginning with / is only intended to be used to link directly to the root, or to be used by sites stored at the root (in this case it wouldn't make much sense?) ?
The leading '/' at the start of the URL informs the web browser that the path given is absolute (with respect to the web server root), i.e. if you link to /posts then you know that the resulting link will be to http://www.mysite.com/posts.
If you don't supply the leading '/' (and you don't give a complete url like http://www.mysite.com/posts) then usually the url is relative, and any page given will be relatvie to the page currently being viewed.
For example:
page being viewed link url target page
------------------------------------------------------------------------------
www.mysite.com/site link.html www.mysite.com/site/link.html
www.mysite.com/site ../link.html www.mysite.com/link.html
www.mysite.com/some/other/page link.html www.mysite.com/some/other/page/link.html
www.mysite.com/some/other/page ../../../link.html www.mysite.com/link.html
The decision on whether to use absolute or relative links is entirely up to you - the advantage of relative links is that if your site moves, links between pages on your site will still work correctly (for example if your site moves to www.mysite.com/otherpath, then any absolute links such www.mysite.com/originalpath/home will no longer work.
You should see the following site for a more complete explanation of relative urls:
Relative URLs (WebReference.com)
Your site root is localhost although you assume that site is your site root. When you use / it is relative to localhost as it is an absolute link.
Try doing it < a href="../posts" >
./ Means base directory, or home
../ Means one directory up