Pokemon.java
package com;
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("/Pokemon")
public class Pokemon extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String num = request.getParameter("pokemon");
int pNum = Integer.parseInt(num);
response.setCharacterEncoding("EUC-KR");
PrintWriter out = response.getWriter();
out.print("<html>");
out.print("<head>");
out.print("<style> img{width:1000px; height:1000px;} div{text-align:center;}</style>");
out.print("</head>");
out.print("<body>");
out.print("<div>");
if (pNum == 1) {
out.print("<img src = dinosaur.PNG>");
} else if (pNum == 2) {
out.print("<img src = turtle.png>");
} else if (pNum == 3) {
out.print("<img src = frog.PNG>");
} else {
}
out.print("</div>");
out.print("</body>");
out.print("</html>");
}
}
selectNum.html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<style type="text/css">
div {
width: 100%;
text-align: center;
}
</style>
</head>
<body>
<div>
<h1>원하는 포켓몬을 입력해주세요</h1>
<br>
<p>* 하나만 입력할 것</p>
<p>1. 파이리 2. 꼬부기 3. 이상해씨</p>
<form action="Pokemon">
<input type="text" name="pokemon"> <input type="submit"
value="확인">
</form>
</div>
</body>
</html>
'Programming > Servlet & JSP' 카테고리의 다른 글
학점 계산 (html 입력, jsp 계산, 출력) (0) | 2020.02.19 |
---|---|
오류페이지 화면 (오류 메세지 가리기) (0) | 2020.02.19 |
URL Mapping (url 맵핑) (0) | 2020.02.19 |
servlet에서 ip체크, 구분하여 화면 보여주기 (0) | 2020.02.19 |
체크박스(checkbox) 값 servlet으로 전달 (0) | 2020.02.19 |