본문 바로가기
코딩수업/AWS 클라우드환경 네이티브

10/26 JSP

by 인생즐겜러 2022. 10. 27.
728x90
반응형

AWS 클라우드환경 네이티브 수업 108 일차

 

 

 

진행

1. html과 JSP 연결로 이것 저것 함

2. 쿠키 / 세션/ HttpServletRequest 를 html과 JSP 연결로 사용

 

 

 

 

 

요약

1. 웹 컨테이너 버퍼의 크기 확인

2. 웹 어플리케이션의 경로

3. FileReader를 통해 비동기적으로 데이터 읽기

 

 

 

 

 


 

 

 

 

 

웹 컨테이너 버퍼의 크기 확인

페이지 지시자를 통해 buffer의 크기를 정해줄 수 있다.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page buffer="8kb" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>출력 버퍼의 크기</h1>
	<h2><%=out.getBufferSize() %> byte</h2>
</body>
</html>

 

 

 

 

 

웹 어플리케이션의 경로

 

<!-- ApplicationExam.jsp -->

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>ApplicationExam.jsp</title>
</head>
<body>
	<%	String appPath = application.getContextPath(); 
		String filePath = application.getRealPath("/ch02/PinfoInput.jsp");
	%>
	<h1>웹 어플리케이션의 URL 경로 : <%=appPath %></h1>
	<p>/ch02/PinfoInput.jsp의 파일 경로 : <%=filePath %></p>
</body>
</html>

 

 

웹 어플리케이션의 url 경로 = 프로젝트의 경로 (현재 웹 모듈의 경로가 / 로 되어있기 때문에 아무것도 출력되지 않았다.)

 

 

 

 

 

 

FileReader를 통해 비동기적으로 데이터 읽기

 

input.txt 파일



So, three things: a wide screen iPod with touch controls;
a revolutionary mobile phone; and a breakthrough Internet communications device.
An iPod, a phone, and an Internet communicator. An iPod, a phone … Are you getting it?
'These are not three separate devices, this is one device, and we are calling it iPhone.
Today, Apple is going to reinvent the phone.
<br/>
세 가지입니다. 터치로 조작할 수 있는 대화면의 iPod, 혁신적인 휴대폰, 그리고 획기적인 인터넷 통신기기입니다.
iPod, 휴대폰, 그리고 인터넷 통신기기. iPod, 휴대폰. 뭔지 감이 오십니까?
이것들은 각각 3개의 제품이 아닙니다. 단 하나의 제품입니다.
우리는 이 새로운 제품을 'iPhone'이라고 부릅니다.
오늘, Apple은 휴대폰을 재발명할 것입니다.

 

<!-- FileReader.jsp -->

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>FileReader.jsp</title>
</head>
<body>
	<%
		BufferedReader reader = null;
	
		try {
			String filePath = application.getRealPath("/WEB-INF/input.txt");
			reader = new BufferedReader(new FileReader(filePath));
			
			while(true) {
				String str = reader.readLine();	// 데이터를 한 줄 읽어서 변수에 저장한다.
				if(str == null)	// 읽어올 데이터가 없다면
					break;		// 반복문을 벗어난다.
				out.println("<h2>" + str + "</h2>");
			}
			
		} catch (FileNotFoundException fnfe) {
			out.println("파일이 존재하지 않습니다.");
		} catch (IOException ioe) {
			out.println("파일을 읽어들이는데 문제가 발생하였습니다.");
		} catch (Exception e) {
			out.println("예상외의 문제가 발생하였습니다.");
		} finally {
			try {
				reader.close();
			} catch (Exception e) {
				out.println("BufferedReader 자원을 닫는데 문제가 발생하였습니다.");
			}
		}
	%>
</body>
</html>

 

 

 

 

 

 

 

728x90
반응형

'코딩수업 > AWS 클라우드환경 네이티브' 카테고리의 다른 글

10/27 웹 제작 - 쿠키 / 세션 / 에러처리  (0) 2022.11.16
11/15 웹 제작 - 파일 업로드 만들기  (0) 2022.11.15
10/25 JSP  (0) 2022.10.26
10/24 JSP의 요소  (0) 2022.10.24
10/17~21 자습  (0) 2022.10.24

댓글