chubbsondubs chubbsondubs - 7 months ago 53
Java Question

Return a static html without redirect in Spring

So I'd like to return an HTML page without sending a redirect. The reason being is using a redirect changes the URL in the browser, and I can't redirect someone to the login if they aren't logged in. What's the most straight forward way to do this? Seems like it should be simple without using jsp or other server side view technologies.

ug_ ug_

You can use forward.


say /static/myWebpage.html is your static html page

This code will return the content of myWebpage.html without changing the url

public class TestingController {
    public String someOtherPage(HttpServletRequest request, HttpServletResponse response) {
        return "forward:/static/myWebpage.html";

Again your url would be "localhost/path/page" but you will be viewing "localhost/static/myWebPage.html"