EX1>



layout_jstl.jsp

; 초기 화면 

; header(홈으로,회사소개,제품소개,질문게시판)과 footer, 메인으로 구분

; header의 메뉴를 클릭하면 main만 변경됨.( main, item, company, qna )

<%@ 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 content=request.getParameter("page");

if(content==null){

content="main.jsp";

}

%>

<div >

<jsp:include page="header.jsp"/>

</div>

<div>

<!-- content변수에 저장되에 있는 페이지가 포함된다. -->

<jsp:include page="<%=content %>"/>

</div>

<div>

<jsp:include page="footer.jsp"/>

</div>

</body>

</html>



header.jsp

<%@ 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>

<style type="text/css">

#header{

width:1000px;

height: 100px;

text-align: right;

background-color: pink;

margin: auto;

}

</style>

</head>

<body>

<div id="header">

<a href="layout_jstl.jsp?page=main.jsp">홈으로</a>|

<a href="layout_jstl.jsp?page=company.jsp">회사소개</a>|

<a href="layout_jstl.jsp?page=item.jsp">제품소개</a>|

<a href="layout_jstl.jsp?page=qna.jsp">질문게시판</a>

</div>

</body>

</html>



main.jsp

<%@ 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>

<style type="text/css">

#content{

width:1000px;

height: 600px;

background-color: orange;

margin: auto;

}

</style>

</head>

<body>

<div id="content">

<h2>우리우리홈쇼핑입니다.</h2>

</div>

</body>

</html>



company.jsp

<%@ 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>

<style type="text/css">

#content{

width:1000px;

height: 600px;

background-color: purple;

margin: auto;

}

</style>

</head>

<body>

<div id="content">

<h2>우리회사소개</h2>

<div>

우리회사는 좋은 회사예요~~~

</div>

</div>

</body>

</html>



item.jsp

<%@ 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>

<style type="text/css">

#content{

width:1000px;

height: 600px;

background-color: silver;

margin: auto;

}

</style>

</head>

<body>

<div id="content">

<h2>제품소개</h2>

<ul>

<li><a href="">제품1</a></li>

<li><a href="">제품2</a></li>

<li><a href="">제품3</a></li>

<li><a href="">제품4</a></li>

</ul>

</div>

</body>

</html>



qna.jsp

<%@ 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>

<style type="text/css">

#content{

width:1000px;

height: 600px;

background-color:lime;

margin: auto;

}

</style>

</head>

<body>

<div id="content">

<h2>질문게시판</h2>


</div>

</body>

</html>



footer.jsp

<%@ 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>

<style type="text/css">

*{

margin:0px;

}

#footer{

width:1000px;

height: 100px;

text-align: right;

background-color:aqua;

margin: auto;

}

</style>

</head>

<body>

<div id="footer">

교육센터주소:서울시 종로구 xxx<br/>

문의전화:02-xxx-xxxx<br/>

이메일:xxx

</div>

</body>

</html>


'WEB > JSP' 카테고리의 다른 글

26. Filter  (0) 2013.04.24
25. error page  (0) 2013.04.23
23. include  (0) 2013.04.23
22. JSTL  (0) 2013.04.23
21. EL( Expression Language )  (0) 2013.04.23

include지시어 

; <%@include file="abc.jsp" %>

; 원래 페이지 안으로 include지시어로 지정한 페이지의 소스코드가 그대로 복사되어 들어감.

; 정적인 페이지(저작권 표시 등) 포함시킬때 주로 사용.



include 액션

; <jsp:include page="abc.jsp"></jsp:include>

; 제어권 자체가 include액션으로 지정된 페이지로 넘어갔다가 처리 후 원래 페이지로 돌아온다.

; 동적인 페이지를 포함시키고자 할때 주로 사용.



<jsp:include page="이동할페이지">

<jsp:param name="파라미터 이름1" value="파라미터 값1" />

<jsp:param name="파라미터 이름2" value="파라미터 값2" />

</jsp:include>



GET방식 전송 시 

<jsp:include page="페이지.jsp?id=abc&pwd=1234" />














'WEB > JSP' 카테고리의 다른 글

25. error page  (0) 2013.04.23
24. 템플릿 페이지  (0) 2013.04.23
22. JSTL  (0) 2013.04.23
21. EL( Expression Language )  (0) 2013.04.23
20. <jsp:forward /> 액션태그  (0) 2013.04.23
JSTL 라이브러리 다운 >>


1.  http://http://jstl.java.net/  접속


2. download JSTL


3. JSTL api

  - javax.servlet.jsp.jstl-1.2.1.jar 다운

  - javax.servlet.jsp.jstl-api-1.2.1.jar 다운


4. WEB-INF/lib 밑에 복사 하고 사용.

 


스크립트 위에 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>   해준다. 

lib밑에 복사가 안되어 있으면 위의 태그 자동생성 안된다.




출력 태그: <c:out>

변수설정 및 삭제 태그 : <c:set> <c:remove>


EX1>

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

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

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!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>


<!-- 변수선언 -->

<c:set var="name" value="홍길동"/>


<!-- jstl로 선언된 변수는 el로만 출력가능하다. -->

이름:${name }<br/>


<!-- 변수수정하기 -->

<c:set var="name" value="김길동"/>

수정된이름:${name }<br/>


<!-- 변수삭제하기 -->

<c:remove var="name"/>

삭제후:${name }<br/>


<%

String id="abcd";

%>

<c:set var="id" value="<%=id %>"/>

id : ${id }

<c:set var="today" value="<%=new Date() %>"/>

today: ${today }

</body>

</html>



<c:if test="{조건식}" var ="변수명" scope="범위">
var ="변수명" - 조건처리 결과를 저장.

EX2>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!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>
<%-- 
[ if문 형식 ]
<c:if test="{조건식}">
   실행문장;
   ...
</c:if>
 --%>
<%
String id="admin";
request.setAttribute("id", id);
%>
<c:if test="${ requestScope.id=='admin' }">
관리자로 로그인하셨습니다.<br/>
</c:if>
<!-- if elseif에 해당하는 choose사용하기 -->
<c:choose>
<c:when test="${ id=='admin' }">
당신은 관리자로 로그인했습니다.<br/>
</c:when>
<c:when test="${ id=='user' }">
당신은 일반사용자로 로그인했습니다.<br/>
</c:when>
<c:otherwise><!--  조건이 맞지 않을때 수행 -->
당신은 손님으로 로그인했습니다.<br/>
</c:otherwise>
</c:choose>
</body>
</html>


<c:forEach>
<c:forEach items="객체명" begin="시작인덱스" end="끝인덱스" step="증감식" var="변수명" varStatus="상태변수">
; items에 collection이나 배열형태의 객체 지정하여 객체의 index만큼 반복 가능.
; begin,end로 원하는 만큼 반복 수행.

EX3>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!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>
<c:forEach var="i" begin="1" end="100" step="2">
${ i } &nbsp;&nbsp;&nbsp;
</c:forEach>
<br/>
<!--  1~100합 -->
<c:forEach var="i" begin="1" end="100" >
<c:set var="sum" value="${ sum+i }"/>
</c:forEach>
1부터 100까지 합: ${ sum }<br/>
</body>
</html>



<c:forTokens>

; 자바의 for문과 StringTokenizer객체를 결합한형태.
; items에 지정한 값을 delims속성의 구분자로 나눈후 나눠진 만큼 반복을 수행.
items, delims, var 속성만으로도 수행가능.

<c:forTokens items="객체명" delims="구분자" begin="시작인덱스" end="끝인덱스" step="증감식" var="변수명" varStatus="상태변수">



<c:choose>
; switch문과 비슷.

<c:choose>
<c:when test="조건"></c:when>
<c:otherwise></c:otherwise>
</c:choose>





'WEB > JSP' 카테고리의 다른 글

24. 템플릿 페이지  (0) 2013.04.23
23. include  (0) 2013.04.23
21. EL( Expression Language )  (0) 2013.04.23
20. <jsp:forward /> 액션태그  (0) 2013.04.23
19. 경로  (0) 2013.04.23


EL( Expression Language )


- 표현 언어

- EL은 스크립트릿<% %> 또는 표현식<%= %>을 좀더 간단하고 이해하기 쉽도록 표현하며, 속성값들을 좀더 쉽게 접근할수 있다.

- EL은 내장객체를 가지고 있어 코드를 줄일수 있고 JSTL과 같이 사용된다.


1) 형식 ${표현식}


2) EL연산자들

   [],.,(),-,not,empty,*,/,+,div,%,mod, <,>,<=,>=,   lt,gt,le,ge,!,==,!=,eq,ne,&&,and,||,or,...


3) EL 내장객체

pageScope,requestScope,sessionScope,applicationScope,param, paramValues, header, headerValues, cookie, initParam,..





EX>


<%@page import="test.beans.Member"%>

<%@ 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>

 10 + 20 = <%=10 + 20%><BR/>

 위의 문자를 el로 바꿔보면<br/>

 10 + 20 = ${10 + 20 }<br/> 

 10==20 : ${10==20}<br/>

 10>20: ${10 gt 20}<br/>

 10 &lt; 20 : ${10 lt 20 }<br/>

 8 mod 5: ${8 mod 5}<br/>

 8%5: ${ 8 % 5 }<br/>

 

 <%

  String id="song";

    String pwd="1234";

    request.setAttribute("id",id);

    request.setAttribute("pwd",pwd);

    session.setAttribute("name", "홍길동");

  %>

<%-- 

<%

  String id1 = (String)request.getAttribute("id");

  String pwd1 = (String)request.getAttribute("pwd");

 %>

 id:<%=id1 %><br/>

 pw:<%=pwd1 %><br/>

  --%>

  <!--  el로 바꿔보면  -->

  id:${requestScope.id }<br/>

  pwd:${requestScope.pwd }<br/>

  

  <%--

  EL은 스코프에 대한 내장객체를 갖고 있어 스코프에 저장된 속성들을 쉽게 접근할 수 있다.

  pageScope, requestScope, sessionScope, applicationScope

  ==> 스코프객체는 생략가능하며, 스코프명이 생략되면

  page < request < session < application 순으로 자동 찾아준다.

   --%>

   

  name:${sessionScope.name }<br/>

  name:${name}<br/> <!-- 중복이 아닌경우 이름만 써도 찾아 준다. -->

  

  <%--

  내장객체 : param --> 파라미터에 대한 정보를 갖음.

   --%>

   <!--  파라미터로 전달된 num값 얻어오기 

   http://localhost:8081/day07_jstl/test01_EL.jsp?num=100&name=kim

   -->

   num:${ param.num }<br/>

   name:${ param.name }<br/>

   

   <%

      Member vo = new Member("song","1234","song@daum.net","010-111-1234",null);

         //세션에 vo 객체 담기

         session.setAttribute("vo", vo);

      %>

   <%

   Member mm=(Member)session.getAttribute("vo");

   %>

아이디:<%=mm.getId() %>   <br/>

비밀번호:<%=mm.getPwd() %><br/>

이메일:<%=mm.getEmail() %></br>

전화번호:<%=mm.getPhone() %></br>


EL로 바꿔보면<BR/>

<!-- 내부적으로 getter메소드가 호출됨. -->

아이디:${sessionScope.vo.id }<br/>

비밀번호:${sessionScope.vo.pwd }<br/>


 </body>

</html>






'WEB > JSP' 카테고리의 다른 글

23. include  (0) 2013.04.23
22. JSTL  (0) 2013.04.23
20. <jsp:forward /> 액션태그  (0) 2013.04.23
19. 경로  (0) 2013.04.23
18. Cookie & session  (0) 2013.04.23
  • 페이지 흐름 제어
  • <jsp:forward page="이동할 페이지" />
  • <jsp:forward page="이동할 페이지">
        <jsp:param name="파라미터 이름1" value="파라미터값1" />
        <jsp:param name="파라미터 이름2" value="파라미터값2" />
        ...
    </jsp:forward>
  •  GET방식으로 전송시에는
    <jsp:forward page="이동할 페이지.jsp?파라미터 이름1=파라미터 값1&파라미터 이름2=파라미터 값2&.."/> 
    도 가능하다.



Ex1>

forwardTest.jsp

; 이름과 주소 입력 후 전송.

; hidden으로 forward 페이지 전송.

<%@ 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>

<form action="forwardTest1.jsp" method="post">

<input type="hidden" name="forwardPage" value="forwardTest2.jsp">

<table>

<tr>

<td>이름</td>

<td><input type="text" name="name" ></td>

</tr>

<tr>

<td>주소</td>

<td><input type="text" name="address" ></td>

</tr>

<tr><td>

<input type="submit" value="전송"/>

</td></tr>

</table>

</form>

</body>

</html>





forwardTest1.jsp

; 중간에 페이지 주소 받아 forward함.

; 전화번호 삽입 후 전송.

<%@ 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>

<% request.setCharacterEncoding("euc-kr"); %>

<jsp:forward page="<%= request.getParameter(\"forwardPage\") %>">

<jsp:param value="010-111-1111" name="tel"/>

</jsp:forward>

</body>

</html>



forwardTest2.jsp

; 이름,주소,tel 모두 전송됨.

<%@ 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>

이름 : <%=request.getParameter("name") %><br>

주소:<%=request.getParameter("address") %><br>

tel:<%=request.getParameter("tel") %>

</body>

</html>



'WEB > JSP' 카테고리의 다른 글

22. JSTL  (0) 2013.04.23
21. EL( Expression Language )  (0) 2013.04.23
19. 경로  (0) 2013.04.23
18. Cookie & session  (0) 2013.04.23
17. Thumbnail 이미지  (0) 2013.04.23

+ Recent posts