2014년 4월 14일 월요일

[Java]Model1타입의 구구단 출력

1. dan_form.html
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="EUC-KR">
  5. <title>Insert title here</title>
  6. </head>
  7. <body>
  8.     <!--
  9.     2. two.jsp - model1
  10.      -->
  11.     <form method="post" action="/Three">
  12.         단을 입력하세요
  13.         <input type="text" name="dan">
  14.         <input type="submit">
  15.     </form>
  16. </body>
  17. </html>
2. two.jsp
  1. <%@ page language="java" contentType="text/html; charset=EUC-KR"
  2.     pageEncoding="EUC-KR"%>
  3. <%@ page import="com.example.*" %>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <%
  12.     int dan = Integer.parseInt(request.getParameter("dan"));
  13.     GuGu gugu = new GuGu();
  14.     String str = gugu.danPrint(dan);
  15.     out.print(str);
  16. %>
  17. </body>
  18. </html>
3. GuGu.java
  1. package com.example;
  2.  
  3. public class GuGu {
  4.     public String danPrint(int dan){
  5.         String output="";
  6.         for(int i=1; i<10; i++){
  7.             output += dan+"*"+i+"="+(dan*i)+"<br>";
  8.         }
  9.         return output;
  10.     }
  11. }

댓글 없음:

댓글 쓰기