我正在尝试从数据库中找到他的姓氏作为“旅行者”,然后将其返回以查看,但出现错误
我还可以在控制台中看到已找到游客,但是当我想将对象传递给观看者时问题就开始了。
我打开页面通过以下代码查找游客:
<form:form method="GET" action="/space.flights/tourist/find">
<input type="submit" value="Find Tourist" />
</form:form></td>
这是要找到的页面:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>List of tourist</title>
</head>
<body>
<form:form method="post" action="found">
<table>
<tr>
<td>Last Name :</td>
<td><form:input path="lastName" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Find" /></td>
</tr>
</table>
</form:form>
</body>
</html>
然后是控制器:
@RequestMapping("/find")
public ModelAndView find() {
ModelAndView model = new ModelAndView("tourist/find", "command", new Tourist());
return model;
}
@RequestMapping(value = "/found", method = RequestMethod.POST)
public ModelAndView found(@ModelAttribute("lastName") String lastName) {
System.out.println("LOOKING " + lastName);
Tourist tourist = touristService.findTourist(lastName);
System.out.println("FOUND: " + tourist.toString() + "FROM = " + lastName);
return new ModelAndView("redirect:/tourist/found");
}
显示结果的页面:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Tourist</title>
</head>
<body>
<table border="2" width="70%" cellpadding="2">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Gender</th>
<th>Country</th>
<th>Notes</th>
<th>Birth</th>
</tr>
<c:out value="${tourist}">
<tr>
<td>${tourist.firstName}</td>
<td>${tourist.lastName}</td>
<td>${tourist.gender}</td>
<td>${tourist.country}</td>
<td>${tourist.notes}</td>
<td>${tourist.birth}</td>
</tr>
</c:out>
</table>
</body>
</html>
我尝试更改POST和GET,但也许我不了解其中的内容。我以为我需要在这里POST发送我的数据。也许问题出在其他地方?