본문 바로가기

Python_WEB/JSP

[Ch15]JSP 연습문제 7

반응형

Q>

main.html과 result.jsp를 작성한다.

main.html에서는 다음과 같이 연산 중의 하나를 선택하고 사용자로부터 피연산자를 입력받을 수 있는 양식을 표시한다.

사용자가 쿼리 전송을 클릭하면 result.jsp를 호출한다.

result.jsp에서는 main.html에서 넘어온 2개의 피연산자를 가지고 지정된 연산을 한 후에 결과를 화면에 출력한다.

 

A>

<!DOCTYPE html>
<html lang="ko">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSP Quiz 7</title>
</head>

<body>
    <form method="GET" action="result_1.jsp">
        <hr>
        <input type="radio" name="calc" value="1" checked>
        <label for="add">덧셈<br /></label>

        <input type="radio" name="calc" value="2">
        <label for="mul">곱셈<br /></label>

        <input type="radio" name="calc" value="3">
        <label for="div">나눗셈</label>
        <hr>
        첫번째 연산자 <input type="text" name="a" id="a"><br />
        두번째 연산자 <input type="text" name="b" id="b"><br />
        <input type="submit" value="쿼리 전송">
    </form>
</body>

</html>

 

<%@ page contentType="text/plain; charset=utf-8" trimDirectiveWhitespaces="true" %>
    <%@ page pageEncoding="utf-8" %>

        <% String a="0" ; String b="0" ; int result=0; String calc; calc=request.getParameter("calc"); if( calc !="" ) {
            a=request.getParameter("a"); b=request.getParameter("b"); switch ( Integer.parseInt(calc) ){ case 1 :
            result=Integer.parseInt(a) + Integer.parseInt(b); break; case 2 : result=Integer.parseInt(a) *
            Integer.parseInt(b); break; case 3 : result=Integer.parseInt(a) / Integer.parseInt(b); break; } }
            out.print("연산의 결과는 " + result +" 입니다."); %>

 

R>

 

HTML5 + CSS3 + JavaScript로 배우는 웹프로그래밍 기초
국내도서
저자 : 천인국
출판 : 인피니티북스 2013.12.19
상세보기
반응형

'Python_WEB > JSP' 카테고리의 다른 글

[Ch15]JSP 연습문제 6  (0) 2021.01.02
[Ch15]JSP 연습문제 5  (0) 2021.01.02
[Ch15]JSP 연습문제 4  (0) 2021.01.02
[Ch15]JSP 연습문제 3  (0) 2021.01.01
[Ch15]JSP 연습문제 2  (0) 2021.01.01