Model(JavaBeans),View(Jsp),Controller(Servlet)を連携させ以下のアプリを作成せよ。

[実行画面]
1.画面にフォームが表示される

2.インチを入力し送信を押すとインチをセンチに変換した値を表示する。
なお、1インチは2.54センチである。

[作例]
●モデル
model.InchCm.java

package model;

import java.io.Serializable;

public class InchCm implements Serializable{
	private double inch,cm;
	public InchCm() {}
	public InchCm(double inch) {
		this.inch = inch;
		this.cm=inch*2.54;
	}
	public double getInch() {
		return inch;
	}
	public void setInch(double inch) {
		this.inch = inch;
	}
	public double getCm() {
		return cm;
	}
	public void setCm(double cm) {
		this.cm = cm;
	}
}

●コントローラー
controller.Convert.java

package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.InchCm;

/**
 * Servlet implementation class Convert
 */
@WebServlet("/convert")
public class Convert extends HttpServlet {


	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher rd=request.getRequestDispatcher("/WEB-INF/view/form.jsp");
		rd.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String inchStr=request.getParameter("inch");
		double inch=Double.parseDouble(inchStr);
		InchCm ic=new InchCm(inch);
		request.setAttribute("inchcm", ic);
		RequestDispatcher rd=request.getRequestDispatcher("/WEB-INF/view/result.jsp");
		rd.forward(request, response);
	}

}

●ビュー
/WEB-INF/view/form.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>InchCmコンバーター</title>
</head>
<body>
<form action="/inchapp/convert" method="post">
インチを入力<input type="number" name="inch" step=0.1 >
<input type="submit" value="送信">
</form>
</body>
</html>

/WEB-INF/view/result.jsp

%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="model.InchCm"%>
<%
InchCm ic=(InchCm)request.getAttribute("inchcm");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>InchCmコンバーター</title>
</head>
<body>
<p><%=ic.getInch() %>inchは<%=ic.getCm() %>cmです。</p>
<a href="/inchapp/convert">戻る</a>
</body>
</html>