인공지능 5/18

2021. 5. 18. 16:43인공지능 수업(JSP)

#JSP

#인공지능

 

-XML문서로 한글 출력 설정하기

<%@ page contentType="text/xml; charset=utf-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>contentType 디렉티브태그</h2>
<h4>text/html: HTML 출력</h4>
<h4>charset=utf-8</h4>
</body>
</html>

실행결과

 

-날짜 나타내기

<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@ page import="java.util.Date" %>
Today is <%=new Date() %>
</body>
</html>

 

실행결과

 

- page 디렉티브 태그에 현재 웹 페이지의 설명 작성하기

<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@ page info="Date 클래스를 이용한 날짜 출력하기" %>
Today is 나는 김은철<%= new Date() %>
</body>
</html>

 

실행결과

-에러페이지 연동

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Directives Tag</title>
</head>
<body>
	<h4>errorPage 디렉티브 태그</h4>
	에러가 발생했습니다
	<h1> 잠시후에 다시 사용해주세요</h1>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    errorPage="page_errorPage_error.jsp" ----> 이 파일로 감
    %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	String str = null;
	out.println(str.toString());
%>
</body>
</html>

실행결과

 

 

-include 디렉티브 태그로 외부 파일의 내용 포함하기

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@ include file="include01_header.jsp" %>
<h4>----------현재페이지 영역---------</h4>
</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Directives Tag</title>
</head>
<body>
<h4>해더 페이지 영역입니다</h4>
<h4>나는 include01_header.jsp입니다.</h4>
</body>
</html>

 

include를 사용하여 연동해보았다.

 

 

--include 디렉티브 태그로 머리글과 바닥글에 외부 파일 내용 포함하기

<%@ page contentType="text/html; charset=utf-8"%>
<%!
	int pageCount = 0;
	void addCount() {
		pageCount++;
	}
%>
<%
	addCount();
%>
<p>	이 사이트 방문은	<%=pageCount%>번째 입니다.</p>
Copyright ⓒ JSPBook
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Directives Tag</title>
</head>
<body>
	<%@ include file="include02_header.jsp"%>
	<p>방문해 주셔서 감사합니다.</p>
	<%@ include file="include02_footer.jsp"%>
</body>
</html>

include를 통해 연동을 해주었다.

 

--include 디렉티브 태그에 JSTL의 Core 태그를 설정하여 1부터 10까지 출력하기

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Directives Tag</title>
</head>
<body>
	<c:forEach var="k" begin="1" end="10" step="1">
		<c:out value="${k}" />
		<Br>
	</c:forEach>
</body>
</html>

1부터 10까지 나타내주었다.

 

--forward 액션 태그로 현재 날짜와 시각을 출력하는 페이지로 이동하기

 

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<p>오늘의 날짜 및 시각
	<p><%=(new java.util.Date()).toLocaleString()%>
</body>
</html>
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<h2>forward 액션 태그</h2>
	<jsp:forward page="forward_date.jsp" />
	<p>-------------------------------</p>
</body>
</html>

실행결과

-- include 액션 태그에 현재 날짜와 시각을 출력하는 페이지 포함하기

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p>오늘의 날짜와 시각
<p><%= new java.util.Date().toLocaleString() %>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>include 액션 태그</h2>
<jsp:include page="include_date.jsp"></jsp:include>
<p> ----------------------
</body>
</html>

실행결과

--include 액션 태그에 현재 날짜와 시각을 출력하는 페이지 포함하기

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>include 액션 태그</h2>
<jsp:include page="include_date.jsp"></jsp:include>
<p> ----------------------
</body>
</html>

실행결과

 

 

--forward 액션 태그와 param 액션 태그에 아이디와 이름 전달하기

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<p>	아이디 : <%=request.getParameter("id")%>
	<%
		String name = request.getParameter("name");
	%>
	<p>	이 름 : <%=java.net.URLDecoder.decode(name)%>
</body>
</html>

 

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<h3>param 액션 태그</h3>
	<jsp:forward page="param01_data.jsp">
		<jsp:param name="id" value="admin" />
		<jsp:param name="name" value='<%=java.net.URLEncoder.encode("관리자")%>' />
	</jsp:forward>
	<p>Java Server Page
</body>
</html>

실행결과

 

-- include 액션 태그와 param 액션 태그에 제목과 현재 날짜 전달하기

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<%
		String title = request.getParameter("title");
	%>
	<h3><%=java.net.URLDecoder.decode(title)%></h3>
	Today is :<%=request.getParameter("date")%>
</body>
</html>
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<h3>param 액션 태그</h3>
	<jsp:include page="param02_data.jsp">
		<jsp:param name="title" value='<%=java.net.URLEncoder.encode("오늘의 날짜와 시각")%>' />
		<jsp:param name="date" 	value="<%=java.util.Calendar.getInstance().getTime()%>" />
		
	</jsp:include>
</body>
</html>

실행결과

 

 

--useBean 액션 태그에 Date 클래스를 사용하여 현재 날짜와 시각 출력하기

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<jsp:useBean id="date" class="java.util.Date" />
	<p><%
			out.print("오늘의 날짜 및 시각");
		%>	
	<p><%=date%>
</body>
</html>

실행결과

 

 

--자바빈즈 Calculator 를 생성하고 useBaen 액션 태그에 Calculator 클래스를 사용하여 숫자 출력

package ch04.com.dao;

public class Calculator {
	public int process(int n) {
		return n*n*n;
		
	}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="bean" class="ch04.com.dao.Calculator"></jsp:useBean>
<%
	int m =bean.process(5);
	out.print("5의 3제곱 : " + m);
%>
</body>
</html>

실행결과

 

 

--자바빈즈 Person을 생성하고 useBean 액션 태그에 Person 클래스를 사용하여 아이디와 이름 출력

package ch04.com.dao;

public class Person {
	private int id = 20181004;
	private String name = "홍길순";

	public Person() {
		
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}//end class
<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<jsp:useBean id="person" class="ch04.com.dao.Person" scope="request" />
	<p>	아이디 : <%=person.getId()%>
	<p>	이 름 : <%=person.getName()%>
</body>
</html>

실행결과

 

--useBean 액션 태그에 위에서 생성한 자바빈즈 Person으로 아이디와 이름을 설정하여 출력하기

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<jsp:useBean id="person" class="ch04.com.dao.Person" scope="request" />
	<p>	아이디 : <%=person.getId()%>
	<p>	이 름 : <%=person.getName()%>
		<%
			person.setId(20182005);
			person.setName("홍길동");
		%>
		<jsp:include page="useBean03.jsp"/>
</body>
</html>

 

 

실행결과

 

-- setProperty 액션 태그에 자바빈즈 Person으로 아이디와 이름을 설정하여 출력하기

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="person" class="ch04.com.dao.Person"/>
<jsp:setProperty property="id" name="person" value="20182005"/>
<jsp:setProperty property="name" name="person" value="홍길동"/>
<p>아이디: <% out.print(person.getId()); %>
<p>이름: <% out.print(person.getName()); %>
</body>
</html>

 

실행결과

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<jsp:useBean id="person" class="ch04.com.dao.Person"></jsp:useBean>
	<p> 아이디: <jsp:getProperty property="id" name="person"/>
	<p> 이름: <jsp:getProperty property="name" name="person"/>
</body>
</html>

실행결과

 

--getProperty 액션 태그에 자바빈즈 Person 이용하여 아이디와 이름을 전달받아 출력하기

 

<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
<title>Action Tag</title>
</head>
<body>
	<jsp:useBean id="person" class="ch04.com.dao.Person"></jsp:useBean>
	<jsp:setProperty name="person" property="id" value="20182005" />
	<jsp:setProperty name="person" property="name" value="홍길동" />
	<p>	아이디 : <jsp:getProperty property="id" name="person" />
	<p>	이 름 : <jsp:getProperty property="name" name="person" />
</body>
</html>

실행결과

 

 

 

 

 

 

 

 

'인공지능 수업(JSP)' 카테고리의 다른 글

인공지능 5/24  (0) 2021.05.24
인공지능 5/21  (0) 2021.05.21
인공지능 5/20  (0) 2021.05.20
인공지능 5/19  (0) 2021.05.19
인공지능 5/17  (0) 2021.05.17