So what I'm basically trying to do here is get a list of hotels in JSP , from the servlet , without any forms.
This is my 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 function:
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();
}
}
Now I know how to do this via form with get / post , since the servlet has specific functions for that. But how can I send this data without forms ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…