JSP

ex01.jsp

<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>

<%
//	Enumeration<String> headers =request.getHeaderNames();
%>

<!-- http header 출력 -->
<c:forEach var="h" items="${header}">
	${h.key } => ${h.value } <br>
</c:forEach>

<hr>
<p>

<!-- set var="변수명" value="값" -->
<c:set var="browser" value="${header['User-Agent'] }"/>
<c:out value="${browser }" /> <!-- 출력문 -->

<hr>
<c:remove var="browser"/>  변수 삭제
<c:out value="${browser }" />




</body>
</html>

 

accept-language => ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4 
cookie => JSESSIONID=287B956A9E031FD0D1F5CF57B7609181 
host => localhost:7555 
upgrade-insecure-requests => 1 
connection => keep-alive 
dnt => 1 
accept-encoding => gzip, deflate, sdch, br 
user-agent => Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 
accept => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 


Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36


변수 삭제

 

 

 

 

 

 

ex02.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>

<!-- set var="변수명" value="값" scope="사용범위" 

scope="사용범위" page request session application
-->

<%
 pageContext.setAttribute("country", "Korea");
%>



<c:set var="country" value="Korea" scope="page" />
<!-- if test="조건식" -->
<c:if test="${country !=null }">
	국가명  : ${country }
</c:if>

<%

 int[] nums= {10, 70, 80, 90, 100};

%>

<c:set var="num" value="<%= nums %>" />

<!-- forEach var="개별값" items="집합" -->

<c:forEach var="n" items="${num }">
  ${n}, 
</c:forEach>

<br>
<c:set var="season" value="가을" />

<c:choose>
	<c:when test="${season =='봄' }">
		봄*봄
	</c:when>
	<c:when test="${season =='여름' }">
		여름*여름
	</c:when>
	<c:when test="${season =='가을' }">
		가을*가을
	</c:when>
	<c:when test="${season =='겨울' }">
		겨울*겨울
	</c:when>
	<c:otherwise>
		그 외의 계절
	</c:otherwise>
</c:choose>




</body>
</html>


 

국가명 : Korea 10, 70, 80, 90, 100, 
가을*가을

 

 

 

 

 

 

ex03.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>

	<!-- set var="변수명" value="값" scope="사용범위"
기본적으로 String type으로 저장됨
scope 을 생략하면 현재 페이지에서만 사용 가능함

java 				EL 				JSTL
pageContext	 	pageScope			page
request			requestScope		request
session			sessionScope		session
application 	applicationScope 	application

 -->

	<%
		int n = 100;
	%>

	<c:set var="num" value="<%=n %>" scope="page" />

	<%
		int a = (Integer) pageContext.getAttribute("num");
		out.println(a);
	%>

	<br> num : ${pageScope.num }


</body>
</html>


 

기본적으로 String type으로 저장되고  형변환시 에러발생.

으로  다음과 같이 작성

	<%
		int n = 100;
	%>

 

 

100 
num : 100

 

 

 

 

 

 

 

 

 

 

 

jsp

 

about author

PHRASE

Level 60  머나먼나라

청년에게 권하고 싶은 것은 다음 세 마디뿐이다. 즉 일하라. 더욱 더 일하라. 끝까지 일하라. -비스마르크

댓글 ( 4)

댓글 남기기

작성