250x250
Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags more
Archives
Today
Total
관리 메뉴

개린이 개발노트

국비지원 JAVA(자바) 프로그래밍 (application 내장 객체 ) 본문

국비지원(국비교육) 웹 개발자 과정

국비지원 JAVA(자바) 프로그래밍 (application 내장 객체 )

개린이9999 2023. 1. 20. 08:39
728x90

reponse 객체(응답)

sendRedirect -> request, response

forward-> request, response 유지

 

나이를 입력-> 20세 이상인지 아닌지 물어보고-? 20세 이상이면 접속

                                                                              20세 아니면 접속불가

 

<%@ 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>
	<form method="get" action="forwardchk.jsp">
		이름 : <input type="text" name="name"> <br>
		나이 : <input type="text" name="age"> <br>
		<input type="submit" value="접속">
	</form>
	
</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>
		
		<%
			int age = Integer.parseInt(request.getParameter("age"));
			//나이가 20살이상이면 접속페이지로 이동, 아니면 alert 접속불가 전페이지로 이동
			if(age<20) {
		%>
			<script>
				alert("접속불가");
				histroy.go(-1);
			</script>
			<%
			} else {
				RequestDispatcher dispatcher = request.getRequestDispatcher("forwardResult.jsp");
				dispatcher.forward(request,response);
			}
			%>
</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>
<%
	String age = request.getParameter("age");
	String name = request.getParameter("name");
%>
	
	<h1><%=name %>(<%=age %>)님 환영합니다.</h1>

</body>
</html>

application 내장 객체 

하나의 어플리케이션(프로젝트) 내부에서 사용

정보 저장

request-> 다음 페이지에 정보를 전달해서 사용

 

A 페이지 (request 정보저장) -> B 페이지 ( 저장된 정보를 사용) 

-> C 페이지 ( request 사용X) 

 

유효 범위 

page : 해당 하나의 jsp 페이지 ( 그 영역 한페이지)

request : 요청받은 페이지

session : 브라우저

application : 하나의 프로젝트

 

 

728x90