본문 바로가기

기존카테고리/JSP_basic

if문

ifTestForm.jsp



<%@ 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 action="ifTest.jsp" method="post">

이름:<input type="text" name="name"><br>

색선택:

<select name="color">

<option value="blue" selected>파랑색

<option value="green">초록색

<option value="red">빨강색

<option value="yellow">기타

</select>

<input type="submit" value="submit">


</form>


</body>

</html>





--------------------------------------------------------------


ifTest.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>


// POST방식에서 글자 안깨지게 셋팅 - request.setCharacterEncoding("utf-8")

<% request.setCharacterEncoding("utf-8"); %>


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>


<%

String name=request.getParameter("name");

String color=request.getParameter("color");

String selectColor = "";

if(color.equals("blue")){

selectColor="파랑색";

}else if(color.equals("red")){

selectColor="빨강색";

}else if(color.equals("green")){

selectColor="초록색";

}else{

selectColor="기타색";

}

%>


<%=name%>님이 선택한 색상은 <%=selectColor%>입니다.

</body>

</html>

'기존카테고리 > JSP_basic' 카테고리의 다른 글

톰캣 기반에서 JSP 한글처리  (0) 2017.06.27
while문  (0) 2017.06.27
표현식(Expression)  (0) 2017.06.27
스크립트릿(scriptlet)  (0) 2017.06.27
선언문(Declaration)  (0) 2017.06.27