need your help here please.
I have a login page. After I enter username/password, I want to see Dashboard page. But I am getting 404 page not found. Can anyone please tell what is going on here.
When I hit http://localhost:8080 -> It goes to http://localhost:8080/login - Which is expected.
After I enter username/password, it goes to http://localhost:8080 - Expected: to go to Dashboard page i.e. http://localhost:8080/dashboard
@Component public class SimpleAuthenticationSuccessHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { ... redirectStrategy.sendRedirect(request, response, "dashboard"); }
DashboardController.java
@Controller @RequestMapping("/dashboard") public class DashboardController { @RequestMapping("/") String init(){ System.out.println("Dashboard - init()"); return "dashboard_init"; } }
app.component.html
Hello... {{name}} Hello... {{title}} <h1> Welcome {{title}}! </h1> <p>Id: <span>{{greeting.id}}</span></p> <p>Message: <span>{{greeting.content}}!</span></p>
app-routing.module.ts
import {DashboardComponent} from "./dashboard/dashboard.component"; const routes: Routes = [ { path: '', redirectTo: '/login', pathMatch: 'full' }, // { path: 'dashboard', redirectTo: '/dashboard', pathMatch: 'full' }, { path: 'dashboard_init', component: DashboardComponent, data: { title: 'Dashboard' } } ];
dashboard.component.ts
@Component({ selector: 'dashboard-component', templateUrl: './dashboard.component.html', styleUrls: ['./dashboard.component.css'], }) export class DashboardComponent implements OnInit { private currentAssociate: Associate; constructor(private http: Http, private router: Router) { } ngOnInit(): void { // initialize services and data this.http .get('/dashboard') .toPromise() .then(response => { let data = response.json(); if (data.currentAssociate) this.currentAssociate = data.currentAssociate as Associate; }) .catch(error => { // this.alertService.error(error); }); } }
dashboard.component.html
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head> <meta charset="utf-8" /> <title>Dashboard</title> </head> <div> <B>Dashboard...</B> </div> </html>
Error: (When the url is http://localhost:8080/dashboard/)
Dashboard - init() [2m2018-03-26 10:07:20.421[0;39m [31mERROR[0;39m [35m13184[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36morg.thymeleaf.TemplateEngine [0;39m [2m:[0;39m [THYMELEAF][http-nio-8080-exec-2] Exception processing template "dashboard_init": Error resolving template "dashboard_init", template might not exist or might not be accessible by any of the configured Template Resolvers [2m2018-03-26 10:07:20.422[0;39m [31mERROR[0;39m [35m13184[0;39m [2m---[0;39m [2m[nio-8080-exec-2][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet] [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "dashboard_init", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause org.thymeleaf.exceptions.TemplateInputException: Error resolving template "dashboard_init", template might not exist or might not be accessible by any of the configured Template Resolvers at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104) at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)