So I start a static web project on eclipse. Let's say MySite. And then I start a jetty web server on eclipse and open localhost:8080 on my browser.
This is what I'll see:
So I go to localhost:8080/MySite/index.html
and see my homepage.
As you can see the the link is not leading where it should be.
It should be going to localhost:8080/MySite/index.html
, or even more preferable, MySite's index page should be hosted on localhost:8080/index.html
and not on some module.
index.html
<!DOCTYPE html>
<html lang="en">
<body>
<a href="/index.html">Home</a>
</body>
</html>
If I were to change this to MySite/index.html it defeats the purpose of it being an http preview server, because MySite will eventually be it's own site and not some kind of module.
How to fix this without using a workaround?
As you can see the the link is not leading where it should be. It should be going to localhost:8080/MySite/index.html, but instead it goes to localhost:8080/index.html
That is because you are using a url form that is relative to server's root /
.
Simply use a ./
(page-relative path) instead of /
(server-root-relative path) in MySite/index.html
.
<!DOCTYPE html>
<html lang="en">
<body>
<a href="./index.html">Home</a>
</body>
</html>
Hope it helps!
Hi there i have worked with tomcat Server with Eclipse , hope this will help .
Have you mentioned your landing page in WEB.xml file . if you have not added your landing page in you web.xml file like the below than add this and try.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Your Website</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With