본문 바로가기
개발/jsp

jsp 기초(출력,달력, 함수)

by 카앙구운 2015. 9. 24.
728x90
반응형

test1.jsp

@Well com찍어보기

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!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=EUC-KR">

<title>Insert title here</title>

</head>

<body>


<% String a="Well Come";%>

<%=a %>

</body>

</html>

================================================================


@import 달력

--------------------------------------------------------------- 

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

    <%@page import="java.util.Calendar"%>

    <%@page import="java.util.Date" %>

    <%@page trimDirectiveWhitespaces="true" %>

<!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=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

Calendar cal=Calendar.getInstance();

Date now=new Date();

%>

오늘은 

<%= cal.get(Calendar.YEAR)%>년

<%= cal.get(Calendar.MONTH)+1%>월

<%= cal.get(Calendar.DATE)%>일

입니다.

현재시각:

<%=now%>


</body>

</html>

================================================================


@for문을 통해 1부터 10까지의 합구하기

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!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=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

int sum=0;

for(int i=1;i<=10;i++){

sum+=i;

}

%>


1부터10까지의 합은 <%=sum %>입니다.

</body>

</html>

================================================================

@함수 적용하기

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%!

public int multiply(int a, int b){

int c=a+b;

return c;

}

%>


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

10 * 25=<%=multiply(10, 25) %>

</body>

</html>

728x90
반응형

'개발 > jsp' 카테고리의 다른 글

jsp URLEncoder  (0) 2015.10.06
jsp 게시판 만들기 1  (0) 2015.09.30
jsp 달력만들기  (0) 2015.09.25
jsp URLEncoder  (0) 2015.09.25
jsp request 메소드 사용  (0) 2015.09.24

댓글