액션 태그 forward
2022. 12. 13. 16:46ㆍJSP
forward_test.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"><!-- form 액션은 안에 들어있는 태그와그 변수정보들을 controller.jsp에 전송해준다 -->
보고싶은 페이지 선택:
<select name="site"><!-- site는 키값 아래가 값중 하나 -->
<option value="naver">네이버</option>
<option value="daum">다음</option>
<option value="google">구글</option>
</select>
<input type="submit" value="전송">
</form>
</body>
</html>
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"); //사이트라는 이름으로 전달된걸 받는다
String url = null;
//url로 일괄처리
switch(site) {
case "naver":
url = "forward_naver.jsp";
break;
case "daum":
url = "forward_daum.jsp";
break;
case "google":
url = "forward_google.jsp";
break;
}
/* if (site.equals("naver")) {
url = "forward_naver.jsp";
} else if (site.equals("google")) {
url = "forward_google.jsp";
} else if (site.equals("daum")) {
url = "forward_daum.jsp";
} */
%>
<!-- 포워드를 사용해서 날려주기 페이지 어디로 가는가? 자바코드의 url변수로 간다 명령 표현식 -->
<jsp:forward page="<%=url%>"></jsp:forward>
</body>
</html>
forward_naver.jsp
<%@ 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>
<script type="text/javascript">
window.open("https://www.naver.com");
</script>
</body>
</html>
forward_daum.jsp
<%@ 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>
<script type="text/javascript">
window.open("https://www.daum.net");
</script>
</body>
</html>
forward_google.jsp
<%@ 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>
<script type="text/javascript">
window.open("https://www.google.com");
</script>
</body>
</html>
'JSP' 카테고리의 다른 글
forward 로그인 (0) | 2022.12.13 |
---|---|
include directive (0) | 2022.12.13 |
Scripting Tag (0) | 2022.12.13 |
directive 태그 (0) | 2022.12.13 |
계산기 (0) | 2022.12.13 |