以下のコードを実行すると
「 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.」
というエラーが発生します。
おそらく、どこかのパスが違う気がするのですが、全くわかりません。
どこが違うのかご教授お願いします。
ディレクトリ
Health.java
package model; import java.io.Serializable; public class Health implements Serializable { private double height, weight, bmi; private String bodyType; public double getHeight() { return height; } public void setHeight(Double height) { this.height = height; } public double getWeight() { return weight; } public void setWeight(Double weight) { this.weight = weight; } public void setBmi(Double bmi) { this.bmi = bmi; } public double getBmi() { return this.bmi; } public void setBodyType(String bodyType) { this.bodyType = bodyType; } public String getBodyType() { return this.bodyType; } }
healthCheck.java
package servlet; 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.Health; import model.HealthCheckLogic; @WebServlet("/healthCheck") public class HealthCheck extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // フォワード RequestDispatcher dispatcher = request.getRequestDispatcher ("/WEB-INF/jsp/healthCheck.jsp"); dispatcher.forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // リクエストパラメータを取得 String weight = request.getParameter("weight"); // 体重 String height = request.getParameter("height"); // 身長 // 入力値をプロパティに設定 Health health = new Health(); health.setHeight(Double.parseDouble(height)); health.setWeight(Double.parseDouble(weight)); // 健康診断を実行し結果を設定 HealthCheckLogic healthCheckLogic = new HealthCheckLogic(); healthCheckLogic.execute(health); // リクエストスコープに保存 request.setAttribute("health", health); // フォワード RequestDispatcher dispatcher = request.getRequestDispatcher ("/jsp/healthCheckResult.jsp"); dispatcher.forward(request, response); } }
healthCheck.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>スッキリ健康診断</title> </head> <body> <h1>スッキリ健康診断</h1> <form action= "HealthCheck" method="post"> 身長:<input type="text" name="height">(cm)<br> 体重:<input type="text" name="weight">(kg)<br> <input type="submit" value="診断"> </form> </body> </html>
HealthCheckLogic.java
package model; public class HealthCheckLogic { public void execute(Health health) { // BMIを算出して設定 double weight = health.getWeight(); double height = health.getHeight(); double bmi = weight / (height / 100.0 * height / 100.0); health.setBmi(bmi); // BMI指数から体格を判定して設定 String bodyType; if (bmi < 18.5) { bodyType = "痩せ型"; } else if (bmi < 25) { bodyType = "普通"; } else { bodyType = "肥満"; } health.setBodyType(bodyType); } }
healthCheckResult.java
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ page import="model.Health" %> <% // リクエストスコープに保存されたHealthを取得 Health health = (Health) request.getAttribute("health"); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>スッキリ健康診断</title> </head> <body> <h1>スッキリ健康診断の結果</h1> <p> 身長:<%= health.getHeight() %><br> 体重:<%= health.getWeight() %><br> BMI:<%= health.getBmi() %><br> 体格:<%= health.getBodyType() %> </p> <a href="/HealthCheck">戻る</a> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/23 05:28
2020/05/23 05:32
2020/05/23 05:42