생활코딩

https://opentutorials.org/course/1
2015. 9. 6. - Hello world! 생활코딩의 세계에 오신 것을 환영합니다. 생활코딩은 일반인들에게 프로그래밍을 알려주는 것을 목적으로 하는 비영리 활동입니다.

1. info_input.jsp 페이지의 입력양식 껍데기 만들기

2. loan_result.jsp 에서 info_input.jsp로부터 넘어온 파라미터 획득하기

3. 2로부터 입력된 파라미터 값들로부터 필요한 연산을 해서 값을 얻어내기

4. 3의 결과를 잘 그려서 출력하기


 



<%@ 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>대출금 이자 계산</title>

</head>

<body>

<center>

<form action="loan_result.jsp" method="post">

<table>

<tr>

<td align="center">대출 원금</td>

<td><input type="text" name="amount"></td>

<td>원</td>

</tr>

<tr>

<td align="center">대출 이율</td>

<td><input type="text" name="rate"></td>

<td>%</td>

</tr>

<tr>

<td align="center">대출 기간</td>

<td><input type="text" name="period"></td>

<td>개월</td>

</tr>

<tr>

<td colspan="3" align="center">

<input type="radio" name="type" value="1" checked="checked">원금 균등 상환

<input type="radio" name="type" value="2">원리금 균등 상환</td>

</tr>

<tr>

<td colspan="3" align="center">

<input type="reset" value="다시입력">

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

</td>

</tr>

</table>

</form>

</center>

</body>

</html>



<%@ 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>대출 이자 계산 결과</title>

</head>

<body>

<%

String amountStr = request.getParameter("amount");

String rateStr = request.getParameter("rate");

String periodStr = request.getParameter("period");

String typeStr = request.getParameter("type");

int amount = Integer.parseInt(amountStr);

double rateDouble = Double.parseDouble(rateStr);

rateDouble /= 100;

rateDouble /= 12;

int period = Integer.parseInt(periodStr);

int type = Integer.parseInt(typeStr);

int repayMonth;

if(type==2)

{

repayMonth = (int) 

((amount

*rateDouble

*Math.pow((1+rateDouble),period))

/(Math.pow((1+rateDouble),period)-1));

}

else

repayMonth = amount / period;

%>

결과를 출력합시다~~~~~~~

<table>

<tr>

<th>회차</th>

<th>상환액</th>

<th>상환원금</th>

<th>이자</th>

<th>대출잔액</th>

</tr>

<% 

int remainAmount = amount;

for(int i = 1; i<=period; i++){

int column1,column2,column3,column4;

column3 = (int)(remainAmount * rateDouble);

if(type==1)

{

column2 = repayMonth;

column1 = column2 + column3;

}

else

{

column1 = repayMonth;

column2 = column1 - column3;

}

remainAmount -= column2;

column4 = remainAmount;

%>

<tr>

<td><%=i %></td>

<td><%=column1 %></td>

<td><%=column2 %></td>

<td><%=column3 %></td>

<td><%=column4 %></td>

</tr>

<%

}

%>

</table>

</body>

</html> 


' IOT 기반 응용 SW과정 > Web Programing' 카테고리의 다른 글

Day37 액션태그  (0) 2016.05.10
Day36 내장 객체의 영역, 액션태그  (0) 2016.05.09
Day34 JSP 내장 객체  (0) 2016.05.03
Day33 Jsp  (0) 2016.05.02
Day32 Web Programming // JSP  (0) 2016.04.29

+ Recent posts