Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse static web project HTTP Preview/Server module conflicts with relative paths

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:

Main HTTP Preview Page

So I go to localhost:8080/MySite/index.html and see my homepage.

Home Page

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?

like image 460
Folaht Avatar asked Jul 28 '17 01:07

Folaht


2 Answers

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!

like image 60
nalinc Avatar answered Sep 17 '22 11:09

nalinc


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>
like image 22
Shrikant Avatar answered Sep 19 '22 11:09

Shrikant