В моем весеннем загрузочном приложении я использую frameset.
Здесь индекс. html:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${appName}">Template title</title>
<link th:href="@{/public/style.css}" rel="stylesheet"/>
</head>
<frameset cols="15%,*">
<frame src="navigator.html" name="navigator" scrolling="no" noresize>
<frame src="welcome.html" name="welcome">
</frameset>
</html>
Здесь IndexController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class IndexController {
@GetMapping("/index")
public String index(Model model) {
return "index";
}
}
WelcomeController. java
@Controller
public class WelcomeContoller {
@Value("${spring.application.name}")
private String appName;
@GetMapping("/welcome")
public String index(Model model) {
model.addAttribute("appName", appName);
return "welcome";
}
}
NavigatorContoller . java
@Controller
public class NavigatorController {
@GetMapping("/navigator")
public String index(Model model) {
return "navigator";
}
}
Здесь конфигурация безопасности:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource; // get by Spring
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
// Here, you are making the public directory on the classpath root available without authentication (e..g. for css files)
.antMatchers("/public/**", "/registration.html").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login.html")
.successHandler((request, response, authentication) -> new DefaultRedirectStrategy().sendRedirect(request, response, "/index"))
.failureUrl("/login-error.html")
.permitAll()
.and()
.logout()
.logoutSuccessHandler(new CustomLogoutSuccessHandler())
.permitAll();
}
приветствуется. html:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<body>
<h1 align="center">Welcome to <span th:text="${appName}">Our App</span></h1>
</body>
</html>
навигатор. html:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p><a href="/users">Users</a></p>
<p> </p>
<!-- By default logout is only triggered with a POST request to "/logout" -->
<form action="#" th:action="@{/logout}" method="post">
<input type="submit" value="Logout"/>
</form>
</body>
</html>
Но при открытом индексе. html фрейм показывается, а страницы внутри фреймов не отображаются (welcome.html, navigator.html
) не показываются. Просто сообщение:
localhost refused to connect.
