일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- AOP-관점지향프로그래밍
- 스프링
- 스프링 팩토리
- 스프링 mybatiis
- 데이터베이스연동
- predestory
- Spring
- 스프링 생성자
- srping 데이터베이스연동
- #인테리어
- 스프링 autowired
- JSP
- 스프링 DB연동
- 스프링 데이터베이스연동
- JSP-서블릿
- #Java
- spring mybatis연동
- 스프링 데이터베이스
- 스프링 마이바티스연동
- #데이터 베이스
- 스프링 setter
- #스프링 셋팅
- 스프링 마이바티스
- 스프링 의존성주입
- AOP-관점지향 프로그래밍(Aspect Oriented Programming)
- 스프링 NamedParameterJDBCTemplate
- 스프링 의존성
- #JSP
- #출처는 페이스북
- 관점지향 프로그래밍
- Today
- Total
재미있게 코딩합시다
JSP - forward 본문
Forward(포워드)
-request스코프에 담긴값 (request,response이 유지된다)
- 이동된 url이 화면에 보이지않는다(사용자는 알수없다)
-포워드 하는법 :
1.<jsp:forward page="이동할페이지">;
2.RequestDispatcher rd = request.getRequestDispatcher("이동할페이지");
rd.forward(request,response);
start.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 이 화면에서는 1,2,3 중 하나를 선택해서 -->
<!-- forwartTest.jsp로 선택한 값을 하나 들고 -->
<!-- 이동하도록 셋팅 -->
<form action="forwardTest.jsp">
<input type="text" name = "num1">
<input type="text" name = "num2">
<select name="type">
<option value="1">1번</option>
<option value="2">2번</option>
<option value="3">3번</option>
</select>
<input type="submit" value="가즈아!!!">
</form>
</body>
</html>
ForwardTest.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String param = request.getParameter("type");
String url = "result.jsp";
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter("num2"));
int result = 0;
if(param.equals("1")){
result = num1 + num2;
}else if(param.equals("2")){
result = num1 - num2;
}else if(param.equals("3")){
result = num1 * num2;
}
//데이터를 리퀘스트 데이터에 담기.
request.setAttribute("result", result);
request.getRequestDispatcher(url).forward(request, response);
%>
</body>
</html>
a.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
여기는 a 라는 페이지입니다.
</body>
</html>
b.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
여기는 b 라는 페이지입니다.
</body>
</html>
c.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
여기는 c 라는 페이지입니다.
</body>
</html>
'IT > JSP' 카테고리의 다른 글
JSP - 코드분리 (0) | 2018.12.26 |
---|---|
JSP-form (0) | 2018.12.26 |
JSP -input (0) | 2018.12.26 |
JSP-구구단 출력하기 (0) | 2018.12.24 |
JSP - 2.서블릿 (0) | 2018.12.24 |