CLASS/JSP
do에서 jsp로 include하여 여러개의 페이지를 로드할 수 있음
hingu
2024. 7. 2. 10:05
1. include
do에서 jsp로 include하여 여러개의 페이지를 로드할 수 있음
- page1.jsp
<body>
<input type="button" value="로그인" onclick="location.href='./page4.do';">
</body>
-page3.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
out.print(request.getAttribute("room"));
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%=request.getAttribute("room_info") %>
</body>
</html>
-page4.do (servlet)
public class page4 extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//여기선 out.print 못씀
response.setContentType("utf-8");
String room = "조선호텔";
String room_info = "중앙 402호";
request.setAttribute("room", room);
request.setAttribute("room_info", room_info);
//dispatcher는 page를 1개만 로드할 수 있음
RequestDispatcher rd = request.getRequestDispatcher("./page3.jsp");
rd.forward(request, response);
}
}