# jsp mvc04

제로·2023년 1월 4일
0

JSP

목록 보기
27/30

3단계 예재

## 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 } // 결과값이 출력


profile
아자아자 화이팅

0개의 댓글