我所要做的基本上是从Servlet中获取JSP酒店列表,而无需任何表单。
这是我的JSP:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<ul>
<c:forEach var="elem" items="${list}">
<li>${elem.name}</li>
</c:forEach>
</ul>
</body>
</html>
Servlet 功能:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
java.util.List<Hotel> list = model.getAllHotels();
request.setAttribute("list", list);
RequestDispatcher rDispatcher = request.getRequestDispatcher("/index.jsp");
rDispatcher.forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
现在我知道如何通过具有特定功能的servlet使用表单进行get / post,但是如果没有表单,我该如何发送这些数据?
http://localhost:8080/yourWebApp/HotelController
。 - JB Nizet