'~/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> " + i + " X " + j + " = " + i*j + " </td>");
}
}
out.print("<tr>");
}//for끝
}
}