[JAVA] 서블릿이용해서 브라우저에 구구단테이블 보여주기

Jong·2021년 9월 14일
0

java

목록 보기
2/2
post-thumbnail

'~/gugudan' url에 구구단 테이블 보여주기

package chap01.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/gugudan")
public class gugudan extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		response.setCharacterEncoding("EUC-KR");
		
		PrintWriter out = response.getWriter();
		
		out.print("<!DOCTYPE html>");
		out.print("<html><head><title>Gugudan</title></head>");
		
		out.print("<style>"+"#head,th,td{"
				+ "border : 1px solid black;"
				+ "border-collapse: collapse;"
				+ " </style>");
		out.print("<table id = \"head\">");
		for(int i = 0; i <= 9; i++){

			out.print("<tr>");
			for(int j = 1; j <= 9; j++){
				if(i == 0) {
					out.print("<th>" + j + "단</th>");
				}
				else {
					out.print("<td>&emsp;" + i + " X " + j + " = " + i*j + "&emsp;</td>");
				}
			}
			out.print("<tr>");
			
		}//for끝
		
	}
	
	
}
profile
새싹 개발자 수련중(블로그 이전)

0개의 댓글