[펌]원문 : http://sugame.tistory.com/273?srchid=BR1http%3A%2F%2Fsugame.tistory.com%2F273
<c:set var="${str}" scope="page">테스트</c:set>
<c:out value="하하하${str}" />
<%
member.setName("테스트");
member.setAge(30);
%>
<!-- 변수 선언 -->
<c:set var="str1" scope="page">는 학생입니다.</c:set>
<c:set var="str2" scope="page" value="는 회사원입니다." />
<!-- 출력문 -->
<c:out value="<b>${member.name}</b>${str1}" escapeXml="false" /><br>
<c:out value="${member.name}${str2}" /><br>
<!-- 빈 클래스에 값 넣기 -->
<c:set target="${member}" property="name">안닝하세요!!!</c:set>
<c:set target="${member}" property="name" value="hello!!" />
<c:out value="${member.name}" />
<c:set var="str1" value="${member.name}" />
<c:set target="${member}" property="name">오리!!</c:set>
<c:out value="${str1}" />
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<jsp:useBean id="member" class="com.test.CMember">
<jsp:setProperty name="member" property="*" />
</jsp:useBean>
<!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>스트럿츠 태그 라이브러리 테스트1</title>
</head>
<body>
<!-- dan 파라메터가 없을 경우 -->
<logic:notPresent parameter="dan">
<b>오류!! dan 파라메터가 null입니다.</b>
</logic:notPresent>
<logic:present parameter="dan">
<!-- dan 파라메터에 값이 없을 경우 -->
<logic:equal parameter="dan" value="">
<b>dan 파라메터에 출력할 구구단의 단(숫자)을 입력하세요</b>
</logic:equal>
<logic:notEqual parameter="dan" value="">
<c:set var="dan" value="<%= request.getParameter("dan") %>" />
<c:if test="${dan > 0 and dan <= 99}">
<c:out value="${dan}"/> 단입니다. <br/>
<table border=1>
<c:forEach var="i" begin="1" end="9" step="1">
<tr>
<td><c:out value="${dan} * ${i} = ${dan*i}"/></td>
</tr>
</c:forEach>
</table>
</c:if>
<!-- else if 문법이 없다. -->
<c:if test="${not (dan > 0 and dan <= 99)}">
<c:out value="1 ~ 99단까지만 출력 가능합니다."/>
</c:if>
</logic:notEqual>
</logic:present>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import = "java.util.Iterator" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<jsp:useBean id="member" class="com.test.CMember">
<jsp:setProperty name="member" property="*" />
</jsp:useBean>
forEach를 이용해 리스트 꺼내오기
<!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>스트럿츠 태그 라이브러리 테스트1</title>
</head>
<body>
<table border="1">
<tr>
<td>번호</td><td>이름</td><td>나이</td>
</tr>
<c:forEach var = "item" items = "${member.memberList}" varStatus = "num">
<tr>
<td><c:out value="${num.count}"/></td>
<td><c:out value="${item.name}"/></td>
<td><c:out value="${item.age}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
if문에 보면 새로운 val 옵션이 있으며 그곳에 식이 참인지 거짓인지 저장된다.
<c:set var="name">홍길동aa</c:set>
<c:if test="${name == '홍길동'}" var="result">
당신은 홍길동입니다.
</c:if>
<c:if test="${not result}">
당신은 홍길동이 아니고 <b>${name}</b> 이군요!!
</c:if>
switch문
<c:set var="age" value="25"/>
<c:choose>
<c:when test="${age < 10}">
당신은 어린 아이군요!
</c:when>
<c:when test="${age < 20}">
당신은 팔팔한 10대군요!
</c:when>
<c:when test="${age < 30}">
당신은 건장한 20대군요!
</c:when>
<c:when test="${age < 40}">
당신은 30대군요!!
</c:when>
<c:otherwise>
당신은 40대 이상입니다.
</c:otherwise>
</c:choose>
-------------------------------------------------------------------------------- setTest1.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR" import="java.util.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- Map 종류가 아닐 경우 --%>
<c:set var="userLevel" scope="session">
Sheriff, Bartender, Cowgirl
</c:set>
<%-- Map 종류일 때 --%>
<%
Hashtable user = new Hashtable();
session.setAttribute("user", user);
%>
<c:set target="${user}" scope="session" property="Level" value="king"></c:set>
<jsp:forward page="setTest2.jsp"/>
-------------------------------------------------------------------------------- setTest2.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- Map 종류가 아닐 경우 --%>
<c:forEach var="content" items="${userLevel}">
userLevle : ${content} <br>
</c:forEach>
<%-- Map 종류일 때 --%>
Map에 세팅한 user Level : ${user.Level}
댓글 없음:
댓글 쓰기