Fundamental Notes/JSP JSP : calc1 빈즈를 이용하지 않음 콩콩댕 2009. 9. 15. 16:17 반응형 <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% int result = 0; if(request.getMethod().equals("POST")) { //클라이언트 쪽에서 입력 받음 3개 //연산자를 가져옴 String op = request.getParameter("operator"); //문자열 형태로 전달되는 인자들을 int로 변환함 int num1 = Integer.parseInt(request.getParameter("num1")); int num2 = Integer.parseInt(request.getParameter("num2")); if(op.equals("+")) { result = num1+num2; } else if(op.equals("-")) { result = num1-num2; } else if(op.equals("*")) { result = num1*num2; } else if(op.equals("/")) { result = num1/num2; } } %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>계산기</title> </head> <body> <center> <H3>계산기</H3> <HR> <%--form 아래에는 서버쪽에서 클라이언트 쪽으로 넘겨서서 보여줄 문서의 일부--%> <form name=form1 method=post> <INPUT TYPE="text" NAME="num1" width=200 size="5"> <SELECT NAME="operator"> <option selected>+</option> <option>-</option> <option>*</option> <option>/</option> </SELECT> <INPUT TYPE="text" NAME="num2" width=200 size="5"> <%-- submit 타입은 submit 수행 --%> <input type="submit" value="계산" name="B1"> <input type="reset" value="다시 입력" name="B2"> </form> <HR> <%-- '= (표현식)인경우에는 write 해주는 것임--%> 계산결과 : <%= result %> </body> </html>