<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>당신이 좋아하는 강아지를 선택 하세요</h1>
	<form action="choiceDog" method="post">
		<input type="checkbox" name="dog" value="pu.jpg"/>푸들
		<input type="checkbox" name="dog" value="jin.jpg"/>진돗개
		<input type="checkbox" name="dog" value="pung.jpg"/>풍산개
		<input type="checkbox" name="dog" value="sap.jpg"/>삽살개
		<input type="submit" value="선택">
	</form>
</body>
</html>

 


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;

/**
 * Servlet implementation class ChoiceDogServlet
 */
@WebServlet("/choiceDog")
public class ChoiceDogServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChoiceDogServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=euc-kr");
		PrintWriter out = response.getWriter();
		String[] dog =request.getParameterValues("dog");
		out.println("<!DOCTYPE html>\r\n" + 
				"<html lang=\"en\">\r\n" + 
				"<head>\r\n" + 
				"    <meta charset=\"UTF-8\">\r\n" + 
				"    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n" + 
				"    <title>Document</title>\r\n" + 
				"</head>\r\n" + 
				"<body bgcolor=\"black\">\r\n" + 
				"    <table align=\"center\" bgcolor=\"yellow\">\r\n" + 
				"        <tr>\r\n");
		for (int i = 0; i < dog.length; i++) {
			out.println("<td>");
			out.println("<imgsrc='"+dog[i]+"'/>");
			out.println("</td>");
		}
		out.println("        </tr>\r\n" + 
				"    </table>\r\n" + 
				"    \r\n" + 
				"</body>\r\n" + 
				"</html>");
	}

}

 

 

(이미지가 없어서 테이블만 테두리만 보임)

+ Recent posts