본문 바로가기

웹 개발/JSP

[Web_JSP] 04

 액션 태그

- 서버나 클라이언트에게 어떤 행동을 하도록 명령하는 태그이다.

- 페이지와 페이지 사이를 제어하거나 다른 페이지의 실행 결과 내용을 현재 페이지에 포함시키거나

   자바빈즈 등의 다양한 기능을 제공한다.

- <jsp: /> 형식으로 사용한다.

 

1. forward(<jsp:forward />)

- 다른 페이지로의 이동, 페이지 흐름을 제어한다.

 

2. include(<jsp:include page="" />)

- 외부 페이지의 내용을 포함하거나 페이지를 분리하여 모듈화 한다.

 

3. param(<jsp:param />)

- 현재 페이지에서 다른 페이지에 정보를 전달한다.

 

 

 

실습(script Tag)

- 문제

<!-- 3행 5열 표를 for문으로 제작하기 -->
<!-- 각 열 안에 몇 행 몇 열인지 출력하기 -->

 

 

- 코드

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>스크립트 태그 실습</title>
</head>
<body>
<%!
	private final int ROW_COUNT = 3;
	private final int COLUMN_COUNT = 5;
%>
<table border="1">
<%
	for(int i=0; i<ROW_COUNT; i++){
%>
	<tr>
	<%
		for(int j=0; j<COLUMN_COUNT; j++){
	%>
		<td><%=i+1%>행<%=j+1%>열</td>
	<%} %>
	</tr>
<%} %>
</table>
</body>
</html>

 

 
결과

 

 

 

 

실습(action Tag(forward))

- 보고 싶은 페이지를 선택한 후 버튼 클릭 시 해당 페이지로 이동

 

1. naver.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script>
	window.open("https://www.naver.com", "_self");
</script>
</html>

 

 

 

2. google.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script>
	window.open("https://www.google.com", "_self");
</script>
</html>

 

 

 

3. daum.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script>
	window.open("https://www.daum.net", "_self");
</script>
</html>

 

 

 

4. controller.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
	<%
		String site = request.getParameter("site") + ".jsp";
/* 		switch(site){
		case "naver":
			break;
		case "google":
			break;
		case "daum":
			break;
		} */
	%>
	<jsp:forward page="<%=site%>"/>
</body>
</html>

 

 

 

5. forwardTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>액션 태그 forward</title>
</head> 
<body>
	<form action="controller.jsp">
		보고 싶은 페이지 선택 : 
		<select name="site">
			<option value="naver">네이버</option>
			<option value="daum">다음</option>
			<option value="google">구글</option>
		</select>
		<input type="submit" value="전송">
	</form>
</body>
</html>

 

결과


 

 

'웹 개발 > JSP' 카테고리의 다른 글

[Web_JSP] 06  (0) 2022.05.24
[Web_JSP] 05  (0) 2022.05.23
[Web_JSP] 03  (0) 2022.05.18
[Web_JSP] 02  (0) 2022.05.17
[Web_JSP] 01  (0) 2022.05.16