## A06_GuguMVC.java
@WebServlet(name = "gugu.do", urlPatterns = { "/gugu.do" })
public class A06_GuguMvc extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//요청값
String num01S = request.getParameter("num01");
String num02S = request.getParameter("num02");
//모델데이터
if(num01S!=null) { //초기화면과 구분하기 위한 조건문
int num01 = Integer.parseInt(num01S);
int num02 = Integer.parseInt(num02S);
request.setAttribute("result", num01+" x "+num02+" = "+(num01*num02));
}
//뷰단 호출
String page="WEB-INF\\a01_mvc\\a06_guguView.jsp";
request.getRequestDispatcher(page).forward(request, response);
}
}
## a06_guguView.jsp
<form>
<select name="num01">
<c:forEach var="grade" begin="2" end="9">
<option>${grade }</option>
</c:forEach>
</select>
X
<select name="num02">
<c:forEach var="cnt" begin="1" end="9">
<option>${cnt }</option>
</c:forEach>
</select>
=? <br>
<input type="submit" value="계산">
</form>
${result } // 결과값이 출력