test5.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>
<form action="test5_ok.jsp" method="post">
<input type="text" name="n1">
<select name="sa">
<option value="">::선택::</option>
<option value="+">더하기</option>
<option value="-">빼기</option>
<option value="*">곱하기</option>
<option value="/">나누기</option>
<option value="%">나머지</option>
</select>
<input type="text" name="n2">
<input type="submit" value="="/>
</form>
</body>
</html>
==============================================================================================================
test5_ok.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int n1=Integer.parseInt(request.getParameter("n1"));
int n2=Integer.parseInt(request.getParameter("n2"));
String sa=request.getParameter("sa");
String i="";
int s=0;
if(sa.equals("+"))
s=n1+n2;
if(sa.equals("-"))
s=n1-2;
if(sa.equals("*"))
s=n1*n2;
if(sa.equals("/"))
s=n1/n2;
if(sa.equals("%"))
s=n1%n2;
%>
<!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>
<%=n1%>
<%=sa%>
<%=n2%>
=
<%=s%>
</body>
</html>
'JSP(Java Server Page)' 카테고리의 다른 글
JSP 기본 예제(태그안의 자바문과 내장객체를 이용한 출력 비교) (0) | 2013.06.25 |
---|---|
JSP 기본 예제(1부터 입력한 값까지의 합) (0) | 2013.06.25 |
JSP 기본 예제(회원가입 양식) (0) | 2013.06.25 |
선언부와 스크립릿의 차이 / 표현식 이용한 출력과 out내장객체를 이용한 출력 (0) | 2013.06.25 |
JSP 기본 예제(표만들기) (0) | 2013.06.25 |