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
'국비지원(국비교육) 웹 개발자 과정' 카테고리의 다른 글
국비지원 JAVA(자바) 프로그래밍 (jsp,param,내장객체,번들,Bundle,fmt) (0) | 2023.01.26 |
---|---|
국비지원 JAVA(자바) 프로그래밍 (JSP,SESSION,로그인, 로그아웃) (0) | 2023.01.25 |
국비지원 JAVA(자바) 프로그래밍 (JSP,표현식,MVC,MVC패턴,오브젝트비교) (0) | 2023.01.19 |
국비지원 JAVA(자바) 프로그래밍 (JSP,SERVLET,서블릿,스크립트릿,선언문) (0) | 2023.01.18 |
국비지원 JAVA(자바) 프로그래밍 (뷰(View), 가상테이블,ERDM,ERDCloud, lucidchart ,JSP,servlet(서블릿)) (0) | 2023.01.17 |