<!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>");
}
}
(이미지가 없어서 테이블만 테두리만 보임)
'Web > Jsp' 카테고리의 다른 글
서블릿 특정 페이지 포워딩(이동) 방식 (0) | 2020.05.26 |
---|---|
서블릿에서 세션 session 살펴보기 (0) | 2020.05.26 |
Postman 프로그램을 이용한 서블릿 테스트 (0) | 2020.05.26 |
MIME 타입 (0) | 2020.05.26 |
JSP 서블릿 한글 깨질 때 / 한글 입력 방법 (0) | 2020.05.26 |