WEB_Programming/JSTL
1. JSTL Out 사용 예제
neokido
2008. 6. 20. 12:37
1. JSTL c:out 예제
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Out Examples</title>
</head>
<body>
<h3>Out Example</h3>
10 * 3 =
<c:out value="${10*3}" />
<br />
</body>
</html>
2. c:out 예제
- 이 예제에서는 c:out value="${변수}" 를 이용하여 출력하는 예제이다.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Query String Example</title>
</head>
<body>Your favorite color is:
<b>
<c:out value="${param.color}" />
</b>
<br />
<br />
Choose your favorite color:
<br />
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=red">
red</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=blue">
blue</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=green">
green</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=yellow">
yellow</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=other">
other</a>
<br />
</body>
</html>
3. 폼에서 전달된 값이 없을경우 Default 값 사용 예제
3.1 formTest.jsp
<html>
<head><title>Create Person</title></head>
<body>
<h1>Enter your details</h1>
<form action="listPageParameters.jsp" method="post">
<table>
<tr><td>First name:</td> <td><input type="text" name="firstName" /></td></tr>
<tr><td>Last name:</td> <td><input type="text" name="lastName" /></td></tr>
<tr><td>Age:</td> <td><input type="text" name="age" /></td></tr>
</table>
<input type="submit" value="Submit details" />
</form>
</body>
</html>
3.2 이 부분에서 폼 값이 없을경우 기본값을 출력하고 있다.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head><title> Display details</title></head>
<body>
<h1>Your details (or, the details that you entered!)</h1>
<table>
<tr><td>First name</td>
<td><c:out value="${param.firstName}" /></td>
</tr>
<tr><td>Last name</td>
<td><c:out value="${param.lastName}" /></td>
</tr>
<tr><td>Age</td>
<td><c:out value="${param.age}" /></td>
</tr>
<%-- The following two values are not passed from the HTML form
and are present to show the syntax for specifying default
values --%>
<tr><td>Partner's name</td>
<td><c:out value="${param.partnerName}" default="Unknown name" /></td>
</tr>
<tr><td>Partner's age</td>
<td><c:out value="${param.partnerAge}">
Unknown age
</c:out>
</td>
</tr>
</table>
</body>
</html>
4. 폼이 없더라도 기본값을 이용하고 있는 예제, 변수에 지정된 값이 없을경우 default에 지정된 "Default Value"가 출력된다.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Out Default Examples</title>
</head>
<body>testit =
<c:out value="${testit}" default="Default Value" />
</body>
</html>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Out Examples</title>
</head>
<body>
<h3>Out Example</h3>
10 * 3 =
<c:out value="${10*3}" />
<br />
</body>
</html>
2. c:out 예제
- 이 예제에서는 c:out value="${변수}" 를 이용하여 출력하는 예제이다.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Query String Example</title>
</head>
<body>Your favorite color is:
<b>
<c:out value="${param.color}" />
</b>
<br />
<br />
Choose your favorite color:
<br />
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=red">
red</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=blue">
blue</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=green">
green</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=yellow">
yellow</a>
<br />
<a
href="<c:out value="${pageContext.request.requestURI}"/>?color=other">
other</a>
<br />
</body>
</html>
3. 폼에서 전달된 값이 없을경우 Default 값 사용 예제
3.1 formTest.jsp
<html>
<head><title>Create Person</title></head>
<body>
<h1>Enter your details</h1>
<form action="listPageParameters.jsp" method="post">
<table>
<tr><td>First name:</td> <td><input type="text" name="firstName" /></td></tr>
<tr><td>Last name:</td> <td><input type="text" name="lastName" /></td></tr>
<tr><td>Age:</td> <td><input type="text" name="age" /></td></tr>
</table>
<input type="submit" value="Submit details" />
</form>
</body>
</html>
3.2 이 부분에서 폼 값이 없을경우 기본값을 출력하고 있다.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head><title> Display details</title></head>
<body>
<h1>Your details (or, the details that you entered!)</h1>
<table>
<tr><td>First name</td>
<td><c:out value="${param.firstName}" /></td>
</tr>
<tr><td>Last name</td>
<td><c:out value="${param.lastName}" /></td>
</tr>
<tr><td>Age</td>
<td><c:out value="${param.age}" /></td>
</tr>
<%-- The following two values are not passed from the HTML form
and are present to show the syntax for specifying default
values --%>
<tr><td>Partner's name</td>
<td><c:out value="${param.partnerName}" default="Unknown name" /></td>
</tr>
<tr><td>Partner's age</td>
<td><c:out value="${param.partnerAge}">
Unknown age
</c:out>
</td>
</tr>
</table>
</body>
</html>
4. 폼이 없더라도 기본값을 이용하고 있는 예제, 변수에 지정된 값이 없을경우 default에 지정된 "Default Value"가 출력된다.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Out Default Examples</title>
</head>
<body>testit =
<c:out value="${testit}" default="Default Value" />
</body>
</html>