简体   繁体   中英

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, ie facebook.com

I'm using Tomcat 7 as my app server.

Thanks

Make it

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

Generating view from servlet is bad idea, use JSTL instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM