1. Get방식과 Post방식
(Jsp 4일차 - request & response참고)
Get방식
일반적으로 하이퍼링크와 같이 사용
① 달력 만들기(calendar.jsp)
Jsp 부분
★ String strYear = request.getParameter("year");
선택하는 순간 값이 올라가서 넘겨진 값을 받는 부분
<%
request.setCharacterEncoding("UTF-8");
Calendar cal = Calendar.getInstance();
//오늘날짜 구하기
int nowYear = cal.get(Calendar.YEAR); //2019
int nowMonth = cal.get(Calendar.MONTH+1); //2
int nowDay = cal.get(Calendar.DAY_OF_MONTH); //15
//★클라이언트에 의해 넘어온 데이터★
String strYear = request.getParameter("year"); //처음 : null ▶2019(입력한 값)
String strMonth = request.getParameter("month"); //처음 : null ▶3
//표시할 달력의 년,월을 담을 변수
int year = nowYear;
int month = nowMonth;
if(strYear!=null)
year = Integer.parseInt(strYear);
if(strMonth!=null)
month = Integer.parseInt(strMonth);
int preYear = year, preMonth = month-1;
if(preMonth<1){
preYear = year-1;
preMonth = 12;
}
int nextYear = year, nextMonth=month+1;
if(nextMonth>12){
nextYear = year+1;
nextMonth = 1;
}
//표시할 달력 셋팅
cal.set(year, month-1, 1);
int startDay = 1;
int endDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
//year년 month월 1일의 week 구하기
int week = cal.get(Calendar.DAY_OF_WEEK);
%>
style부분
<style type="text/css">
body {
font-size: 12pt;
}
td {
font-size: 12pt;
}
</style>
body부분
<body>
</br></br>
<table align="center" width="210" cellpadding="2" cellspacing="1">
<tr>
<td align="center">
<a href="calendar.jsp" style="text-decoration: none;"><img alt="" src="./image/today.jpg" width="30" align="left"></a>
<a href="calendar.jsp?year=<%=preYear%>&month=<%=preMonth%>" style="text-decoration: none;">◀</a>
<b> <%=year%>년 <%=month%>월</b>
<a href="calendar.jsp?year=<%=nextYear%>&month=<%=nextMonth%>" style="text-decoration: none;">▶</a>
</td>
</tr>
</table>
<table align="center" width="250" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#e6e4e6" align="center"><font color="red">일</font></td>
<td bgcolor="#e6e4e6" align="center">월</td>
<td bgcolor="#e6e4e6" align="center">화</td>
<td bgcolor="#e6e4e6" align="center">수</td>
<td bgcolor="#e6e4e6" align="center">목</td>
<td bgcolor="#e6e4e6" align="center">금</td>
<td bgcolor="#e6e4e6" align="center"><font color="blue">토</font></td>
</tr>
<%
int newLine = 0;
out.print("<tr height='20'>");
for(int i=1;i<week;i++){
out.print("<td bgcolor='#ffffff'> </td>");
newLine++;
}
for(int i=startDay;i<=endDay;i++){
//글꼴색
String fontColor = (newLine==0)?"red":(newLine==6)?"blue":"black";
//오늘 날짜 배경색
String bgColor = (nowYear==year) && (nowMonth==month) && (nowDay==i)?"#e6e4e6":"#ffffff";
out.print("<td align='center' bgcolor='" +bgColor+
"'><font color='" +fontColor+ "'>" +i+ "</font></td>");
newLine++;
if(newLine==7 && i!=endDay){
out.print("</tr><tr height='20'>");
newLine=0;
}
}
while(newLine>0 && newLine<7){
out.print("<td bgcolor='#ffffff'> </td>");
newLine++;
}
out.print("</tr>");
%>
</table>
</body>
결과
▶ 클릭
◀클릭
2. include
<%@ include file=”파일명" %>
○ 파일을 불러서 사용할 때 사용
○ 외부에서 만들어진 파일을 불러올 때는 html을 사용하지 않는 경우가 많음 ▶ html이 중복 사용되기 때문에
① test1.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@ include file="abc.jsp" %>
<%=str %>
</body>
</html>
▼ 변경
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
%>
<%@ include file="abc.jsp" %>
<%=str %>
② abc.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String str = "includ 테스트";
%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<b>여기는 abc.jsp파일 입니다!</b></br>
</body>
</html>
결과
'STUDY > JSP' 카테고리의 다른 글
Jsp 6일차 - 액션태그 (0) | 2019.02.19 |
---|---|
Jsp 6일차 - 전송방식 (0) | 2019.02.19 |
Jsp 4일차 - buffer (0) | 2019.02.15 |
Jsp 4일차 - submit & button (0) | 2019.02.15 |
Jsp 4일차 - jsp영역 안에서 html사용 (0) | 2019.02.15 |
댓글