图片1。Successful GET request
图片2. Failed POST when click on submit
欢迎页面,即index.jsp
上的localhost:8080/war_filename
但是当我们单击索引页面中的登录名时,它会显示http状态代码404
那里有人,谁有同样的问题?
我已将战争文件复制到apache\webapps
WebController.java
@Controller
public class indexController {
String errorMessage = "Invalid credentials";
@GetMapping("/login")
public String login() {
return "index.jsp";
}
/*********** Login using form ************/
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestParam("firstname") String firstName,
@RequestParam("lastname") String lastName) {
System.out.println("inside login form");
Customer object = repository.findByFirstNameAndLastName(firstName,
lastName);
if (object != null) {
return "home.jsp";
}
return "index.jsp";
}
}
index.jsp
<h3>Do Login Here</h3>
<form method="POST" action="/login">
<table>
<tr>
<td>Employee ID</td>
<td><input type="text" name="firstname" placeholder="Username" required></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="lastname" placeholder="Password" required></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
home.jsp
<body>
<h3>Operations</h3>
<form action="/selectusingform" method="get">
<a href="selectusingform">Select</a>
</form>
<table>
<tr>
<td><a href="insert.jsp">Insert</a></td>
</tr>
<tr>
<td><a href="update.jsp">Update</a></td>
</tr>
<tr>
<td><a href="delete.jsp">Delete</a></td>
</tr>
<tr>
<td><a href="find.jsp">Find</a></td>
</tr>
</table>