Khalid
Khalid

Reputation: 75

URL in JSP always goes to localhost and gives HTTP Status 404

I'm using a servlet to generate an html page, and in the java I code the URL to output a standard href and it seems to output fine on the page, however when I click on it, I get HTTP Status 404.

In my servlet the code is :-

    out.write("<html>");
    out.write("<body>");
    out.write("<br/>");
    out.write("<a href=\"url\"" + "facebook.com" + "\">" + "facebook.com"
            + "</a>" + "<br/>");
            out.write("</body");
    out.write("</html>");

And it looks fine in the generated html page when I view source.

    <html>
    <body>
    <br/>
    <a href="url"facebook.com">facebook.com</a>
    <br/> 
    </body>
    </html>

However everytime I click it the link appears as .http://localhost:8080/MyProject/url and of course this goes to HTTP Status 404 - /MyProject/url.

Anything I can do to get it to actually go to a URL, i.e. facebook.com

I'm using Tomcat 7 as my app server.

Thanks

Upvotes: 0

Views: 486

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240860

Make it

out.write("<a href='facebook.com'>facebook.com</a> <br/>");

Generating view from servlet is bad idea, use JSTL instead

Upvotes: 1

Related Questions