close

Trust Me!! Trust You!!


  • Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

Found 1 article(s) for '달력'.

  1. 2013/06/04 jsp 달력 예제

jsp 달력 예제

웹 프로그래밍
2013/06/04 16:10
 
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.Calendar"%>

<%
request.setCharacterEncoding("utf-8");
//Calender 클래스는 추상 클래스 이므로 객체생성이 되지 않는다.
//따라서 getInstance() 메서드를 이용하여 하위클래스의 객체를 생성하여 리턴한다.
//하위 클래스는 플랫폼의 나라 언어에 맞는 것을 자동으로 리턴해 줍니다.

//캘린더 객체 생성
Calendar cal = Calendar.getInstance();

//오늘 날짜 구하기
int nowYear=cal.get(Calendar.YEAR);
int nowMonth=cal.get(Calendar.MONTH)+1;

//월은 0부터 시작하므로 1월 표시를 위해 1을 더해 줍니다.
int nowDay=cal.get(Calendar.DAY_OF_MONTH);

//클라이언트가 선택하여 넘어온 날짜
String strYear=request.getParameter("year");
String strMonth=request.getParameter("month");

//표시할 달력의 년,월
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){ //1월 전월은 작년 12월 이니깐...
preYear=year-1;
preMonth=12;
 }

//다음달 구하기
int nextYear=year,nextMonth=month+1;
if(nextMonth>12){ //12월 다음달은 내년 1월 이므로...
nextYear=year+1;
nextMonth=1;
}

//표시할 달력 세팅
cal.set(year,month-1,1); //년,월,일
int startDay=1;//달의 첫 날
int endDay=cal.getActualMaximum(Calendar.DAY_OF_MONTH);

//매년 해당월의 1일 구하기
int week =cal.get(Calendar.DAY_OF_WEEK);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>달력 예제</title>
<style type="text/css">
table{text-align:center; background:#fff;}
table td{border:solid 1px #ccc}
.sun{color:red;}
.sat{color:blue;}
</style>
</head>
<body>

<table align="center" width="210" cellpadding="2" cellspacing="1">
<tr>
<td align="center">
  <a href="scheduleList2.jsp?year=<%=preYear %>&month=<%=preMonth %>">☜</a>
  &nbsp;<%=year %>년&nbsp;&nbsp;<%=month %>월
  <a href="scheduleList2.jsp?year=<%=nextYear %>&month=<%=nextMonth %>">☞</a>
</td>
</tr>
</table>

<!-- 달력표시 -->
<table align="center" width="210" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td class="sun">일</td>
<td>월</td>
<td>화</td>
<td>수</td>
<td>목</td>
<td>금</td>
<td class="sat">토</td>
</tr>
<%
//한주가 지나면 줄바꿈을 할 것이다.
int newLine=0;
out.print("<tr>");
for(int i=1; i < week; i++){
out.print("<td>&nbsp;</td>");
newLine++;
}
for(int i=startDay;i<=endDay;i++){ //1일 부터 말일까지 반복
String fontColor = (newLine == 0) ? "red" : (newLine == 6) ? "blue" : "black";
String bgColor = (nowYear == year) && (nowMonth == month) && (nowDay == i) ? "#e6e6e6" : "#fff";//오늘날짜음영
out.print("<td style='background:" + bgColor + "; color:" + fontColor + "'>" + i + "</td>");
newLine++;
if(newLine == 7 && i != endDay){ //7일째거나 말일이면 달력 줄바꿈이 일어난다.
out.print("</tr><tr>");
newLine=0;
}
} //3항 연산자로 for문으로 요일별 색상을 정한다.
 
while(newLine>0&&newLine<7){ //마지막날 이후 달력 채우기
out.print("<td>&nbsp;</td>");
newLine++;
}
out.print("</tr>");
%>
</table>

</body>
</html>

[출처] jsp 달력 예제|작성자 237

이올린에 북마크하기
TAG Calendar, JSP, 달력
No received trackback. / No comment.

Trackback Address :: http://viper150.cafe24.com/trackback/227

You can also say.

Prev 1 Next
블로그 이미지
이것저것 불펌금지도 퍼다가 담습니다. 외부에 비공개된 페이지 입니다. By. 어른왕자

카테고리

  • 전체 (298)
    • 사는 이야기 (115)
    • 웹 프로그래밍 (102)
    • App 프로그래밍 (22)
    • IT 뉴스&기타 (22)
    • 박한별 (4)
    • 역사&기타지식 (9)

태그목록

  • 마우스막기
  • 스프링
  • 국가통계포털
  • base target
  • 唐田
  • java.util.List
  • ultraeditor
  • BOA
  • 붕당
  • 탕평책
  • 윈도우
  • web.xml
  • Ultra
  • 유머
  • pdf
  • MenuBar
  • Parkoz
  • benchmark
  • linux BOA
  • java api
  • DB2
  • 남성전용
  • 금속
  • 탕수육
  • IU
  • addFlashAttribute
  • C#
  • mybatis
  • 게임의자
  • hwpCtrl

최근에 올라온 글

  • 보험사의 조정신청 대응방법.
  • 어느 천재의 앞선 시선.
  • [병맛더빙] 누구게..... (1)
  • 韓경제 `회색 코뿔소` 상황...
  • SVN Connector 설치 URL.
  • 군대를 가지 않는 서울대생.
  • “운은 하늘의 귀여움 받는...
  • 목장에서 알바하다가 캐스...
  • [펌]믿고 거르는 관상.
  • 하루에 1세트씩 하면 좋다...

최근에 달린 댓글

  • 배우 김정현은 길지 않은 연기... 김정현 04/10
  • 정세균 국무총리는 4일 신종... 정세영 04/07
  • <p> '학폭을 인정한 적 없는'... 이가흔 04/05
  • 장동민은 "물론 전문가분들도... 장동민 04/02
  • <p> '맛남의 광장' 한고은이... 박수홍 04/02

최근에 받은 트랙백

  • Solace Salts Bold Tobacco. Solace Salts Bold Tobacco 03/29
  • read this post from Bookie 7. read this post from Bookie 7 02/28
  • công ty may đồng phục. công ty may đồng phục 01/08
  • Israelnightclub`s recent blo... Israelnightclub`s recent blo.. 01/06
  • Suggested Browsing. Suggested Browsing 01/06

글 보관함

  • 2019/03 (1)
  • 2018/12 (1)
  • 2018/09 (1)
  • 2018/08 (1)
  • 2018/02 (1)

달력

«   2021/04   »
일 월 화 수 목 금 토
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

링크

  • Total : 265342
  • Today : 13
  • Yesterday : 47
Tattertools
Eolin
rss

어른왕자's blog is powered byTattertools1.1.2.2 : Animato