처리해야 할 경우의 수가 3개 이상일 경우에 사용한다.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ifMultiTestForm.jsp</title>
</head>
<body>
<h1>ifMultiTestForm.jsp</h1>
<form method="post" action="ifMultiTestPro.jsp">
이름: <input type="text" name="name"><br>
전화번호: <select name="local">
<option value="서울">서울</option>
<option value="경기">경기</option>
<option value="강원">강원</option>
<option value="울산">울산</option>
</select> - <input type="text" name="tel"><br>
<input type="submit" name="입력완료">
</form>
</body>
</html>
ifMultiTestPro.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ifMultiTestPro.jsp</title>
</head>
<body>
<h1>ifMultiTestPro.jsp</h1>
<%
request.setCharacterEncoding("utf-8"); //post방식 요청에 대한 한글 처리
String name = request.getParameter("name");
String local = request.getParameter("local");
String tel = request.getParameter("tel");
// out.println(name + "<br>");
// out.println(local + "<br>");
// out.println(tel + "<br>");
String strlocal = "";
if(local.equals("서울")){
strlocal = "02";
}else if (local.equals("경기")){
strlocal = "031";
}else if (local.equals("강원")){
strlocal = "033";
}else if (local.equals("울산")){
strlocal = "052";
}
%>
<%=name %> 님의 전화번호: <%=strlocal %>-<%=tel %>입니다.
</body>
</html>
'JSP' 카테고리의 다른 글
JSP페이지의 액션태그 (0) | 2021.01.16 |
---|---|
Switch 문 (0) | 2021.01.16 |
application 내장객체 (0) | 2020.11.14 |
Session 내장객체 (0) | 2020.11.14 |
response 내장객체 - sendRedirect (0) | 2020.11.14 |
댓글