# 조건에 따른 JSP 파일로 이동
...더보기
Source 보기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Selection Page</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div align="center">
<h1 class="rainbow">보고 싶은 것을 선택하시오.</h1>
<form action="select.jsp">
배경 <input type="radio" name="pgm" value="color1"><br /> 구구단
<input type="radio" name="pgm" value="gugu1"><br /> 중앙정보 <input
type="radio" name="pgm" value="response"><br /> <br /> <input
type="submit" value="선택 완료">
</form>
</div>
</body>
</html>
...더보기
Source 보기
<%@ 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>Selection JSP</title>
</head>
<body>
<% String[] color = {"RED", "ORANGE","YELLOW","GREEN","BLUE","NAVY","VIOLET","BLACK"};
int n = (int)(Math.random()*8);
String pgm = request.getParameter("pgm")+".jsp";
System.out.println("pgm --> "+pgm);
RequestDispatcher rd = request.getRequestDispatcher(pgm);
if(pgm.equals("color1.jsp")){
request.setAttribute("color", color[n]);
rd = request.getRequestDispatcher("color1.jsp");
} else if(pgm.equals("gugu1.jsp")){
request.setAttribute("num", n+2);
rd = request.getRequestDispatcher("gugu1.jsp");
}else if(pgm.equals("response.jsp")){
//rd = request.getRequestDispatcher("response.jsp");
}
rd.forward(request, response);
%>
</body>
</html>
선택에 따른 JSP 조건.
RequestDispatcher rd = request.getRequestDispatcher(pgm)
- 선택시 아래의 페이지를 볼수 있다.
'청년취업아카데미 > DayLog' 카테고리의 다른 글
[ JSP ] Day 10 - ③ Error Page 정의하기 (0) | 2019.07.23 |
---|---|
[ JSP ] Day 10 - ② Error 처리하는 방법 (0) | 2019.07.23 |
[ Database ] Day 07 - ② 계층적 질의문 (0) | 2019.07.17 |
[ Database ] Day 07 - ① 동의어(Synonym) (0) | 2019.07.17 |
[ Database ] Day 06. Deadlock and Log (0) | 2019.07.16 |