Nagendra555 Nagendra555 - 1 month ago 6
HTML Question

Spring boot not redirecting to desired page

below is my Controller class.

@Controller
public class BankController {

@Autowired
private CustomerService customerService;
@Autowired
private CustomerRepository customerRepository;

@RequestMapping(value="/login", method=RequestMethod.POST)
public String actionLogin(@RequestParam String email, @RequestParam String password, Model model){
List<Customer> byEmail = customerRepository.findByEmail(email);
Customer customer = byEmail.get(0);
if(BCrypt.checkpw(password, customer.getHashedPassword())){
model.addAttribute("customer", customer);
return "enterSiteView.html";
}


return "errorView.html";
}


I have kept
enterSiteView.html, errorView.html
in templates folder as given in the documentation.
When I click the login button the url does change to
http://localhost:9090/enterSiteView.html
but it displays an error as.

Whitelabel Error Page
application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Oct 23 14:03:43 IST 2016
There was an unexpected error (type=Not Found, status=404).
No message available`


My
enterSiteView.html
has nothing but just a Hello World text.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello Earth</title>
</head>
<body>

</body>
</html>


Login Page:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sign-Up/Login Form</title>
<link href='http://fonts.googleapis.com/css?family=Titillium+Web:400,300,600' rel='stylesheet' type='text/css'>

<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>

<body>

<div class="form">

<ul class="tab-group">
<li class="tab active"><a href="#signup">Sign Up</a></li>
<li class="tab"><a href="#login">Log In</a></li>
</ul>

<div class="tab-content">
<div id="signup">
<h1>Sign Up for Free</h1>

<form action="/register" method="post">

<div class="top-row">
<div class="field-wrap">
<label>
First Name<span class="req">*</span>
</label>
<input type="text" required autocomplete="off"/>
</div>

<div class="field-wrap">
<label>
Last Name<span class="req">*</span>
</label>
<input type="text" required autocomplete="off"/>
</div>
</div>

<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email" required autocomplete="on"/>
</div>

<div class="field-wrap">
<label>
Set A Password<span class="req">*</span>
</label>
<input type="password" required autocomplete="off"/>
</div>

<button type="submit" class="button button-block"/>Get Started</button>

</form>

</div>

<div id="login">
<h1>Welcome Back!</h1>

<form action="/login" method="post">

<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email" id="email" name="email" required autocomplete="off"/>
</div>

<div class="field-wrap">
<label>
Password<span class="req">*</span>
</label>
<input type="password" id="password" name="password" required autocomplete="off"/>
</div>

<p class="forgot"><a href="#">Forgot Password?</a></p>

<button class="button button-block"/>
Log In</button>

</form>

</div>

</div><!-- tab-content -->

</div> <!-- /form -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>

</body>
</html>


I have places index.html in static for the welcomepage. After the login is successful it should redirect to the desired page, instead it shows the above error.

Answer

So you redirecting base on relative path, it means that if you: specify this way :

return "redirect: errorView.html"

it directs you current url + / + errorView.html. if you was on http://example.com/user , you get http://example.com/user/errorView.html

When you use :

return "redirect: /errorView.html"

it directs you context path + / + errorView.html. if you was on http://example.com/user , you get http://example.com/errorView.html

Comments