728x90
반응형

 

 

10_02_makeTime.jsp
10_02_viewTime.jsp

10_02_makeTime.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "java.util.Calendar"%>
<%
	Calendar cal = Calendar.getInstance();
	request.setAttribute("time", cal);
%>
<%-- <% response.sendRedirect("10_02_viewTime.jsp"); %> --%>
<!-- redirect-쿼리스트링 url이므로 대용량x -->
<jsp:forward page="10_02_viewTime.jsp"/>
10_02_viewTime.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import ="java.util.Calendar" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Attribute속성 사용하여 값 설정하고 받기</h1>
<% Calendar cal = (Calendar) request.getAttribute("time"); %>
<!-- Calendar자료형으로 다운캐스팅 -->
현재 시간은
<%= cal.get(Calendar.HOUR_OF_DAY)>9
	?cal.get(Calendar.HOUR_OF_DAY)
	:"0"+cal.get(Calendar.HOUR_OF_DAY) %>시
<%= cal.get(Calendar.MINUTE)>9?cal.get(Calendar.MINUTE):"0"+cal.get(Calendar.MINUTE) %>분
<%= cal.get(Calendar.SECOND)>9?cal.get(Calendar.SECOND):"0"+cal.get(Calendar.SECOND) %>초 입니다.
</body>
</html>
728x90
반응형

+ Recent posts