teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

質問を伏せるための質問修正であったため、復元いたしました。

2020/05/25 08:31

投稿

Aya_nishimura
Aya_nishimura

スコア16

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,155 @@
1
1
  以下のコードを実行すると
2
+ 「 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.」
2
3
  というエラーが発生します。
3
4
  おそらく、どこかのパスが違う気がするのですが、全くわかりません。
4
- どこが違うのかご教授お願いします。
5
+ どこが違うのかご教授お願いします。
6
+ ディレクトリ
7
+ ![イメージ説明](54d2ab35b2b1c47f7baba8e07d2b2a9d.png)
8
+ Health.java
9
+ ```ここに言語を入力
10
+ package model;
11
+ import java.io.Serializable;
12
+ public class Health implements Serializable {
13
+ private double height, weight, bmi;
14
+ private String bodyType;
15
+ public double getHeight() {
16
+ return height;
17
+ }
18
+ public void setHeight(Double height) {
19
+ this.height = height;
20
+ }
21
+ public double getWeight() {
22
+ return weight;
23
+ }
24
+ public void setWeight(Double weight) {
25
+ this.weight = weight;
26
+ }
27
+ public void setBmi(Double bmi) {
28
+ this.bmi = bmi;
29
+ }
30
+ public double getBmi() {
31
+ return this.bmi;
32
+ }
33
+ public void setBodyType(String bodyType) {
34
+ this.bodyType = bodyType;
35
+ }
36
+ public String getBodyType() {
37
+ return this.bodyType;
38
+ }
39
+ }
40
+ ```
41
+ healthCheck.java
42
+ ```ここに言語を入力
43
+ package servlet;
44
+ import java.io.IOException;
45
+ import javax.servlet.RequestDispatcher;
46
+ import javax.servlet.ServletException;
47
+ import javax.servlet.annotation.WebServlet;
48
+ import javax.servlet.http.HttpServlet;
49
+ import javax.servlet.http.HttpServletRequest;
50
+ import javax.servlet.http.HttpServletResponse;
51
+ import model.Health;
52
+ import model.HealthCheckLogic;
53
+ @WebServlet("/healthCheck")
54
+ public class HealthCheck extends HttpServlet {
55
+ private static final long serialVersionUID = 1L;
56
+ protected void doGet(HttpServletRequest request,
57
+ HttpServletResponse response)
58
+ throws ServletException, IOException {
59
+ // フォワード
60
+ RequestDispatcher dispatcher =
61
+ request.getRequestDispatcher
62
+ ("/WEB-INF/jsp/healthCheck.jsp");
63
+ dispatcher.forward(request, response);
64
+ }
65
+ protected void doPost(HttpServletRequest request,
66
+ HttpServletResponse response)
67
+ throws ServletException, IOException {
68
+ // リクエストパラメータを取得
69
+ String weight = request.getParameter("weight"); // 体重
70
+ String height = request.getParameter("height"); // 身長
71
+ // 入力値をプロパティに設定
72
+ Health health = new Health();
73
+ health.setHeight(Double.parseDouble(height));
74
+ health.setWeight(Double.parseDouble(weight));
75
+ // 健康診断を実行し結果を設定
76
+ HealthCheckLogic healthCheckLogic = new HealthCheckLogic();
77
+ healthCheckLogic.execute(health);
78
+ // リクエストスコープに保存
79
+ request.setAttribute("health", health);
80
+ // フォワード
81
+ RequestDispatcher dispatcher =
82
+ request.getRequestDispatcher
83
+ ("/jsp/healthCheckResult.jsp");
84
+ dispatcher.forward(request, response);
85
+ }
86
+ }
87
+ ```
88
+ healthCheck.jsp
89
+ ```ここに言語を入力
90
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
91
+ <!DOCTYPE html>
92
+ <html>
93
+ <head>
94
+ <meta charset="UTF-8">
95
+ <title>スッキリ健康診断</title>
96
+ </head>
97
+ <body>
98
+ <h1>スッキリ健康診断</h1>
99
+ <form action= "HealthCheck" method="post">
100
+ 身長:<input type="text" name="height">(cm)<br>
101
+ 体重:<input type="text" name="weight">(kg)<br>
102
+ <input type="submit" value="診断">
103
+ </form>
104
+ </body>
105
+ </html>
106
+ ```
107
+ HealthCheckLogic.java
108
+ ```ここに言語を入力
109
+ package model;
110
+ public class HealthCheckLogic {
111
+ public void execute(Health health) {
112
+ // BMIを算出して設定
113
+ double weight = health.getWeight();
114
+ double height = health.getHeight();
115
+ double bmi = weight / (height / 100.0 * height / 100.0);
116
+ health.setBmi(bmi);
117
+ // BMI指数から体格を判定して設定
118
+ String bodyType;
119
+ if (bmi < 18.5) {
120
+ bodyType = "痩せ型";
121
+ } else if (bmi < 25) {
122
+ bodyType = "普通";
123
+ } else {
124
+ bodyType = "肥満";
125
+ }
126
+ health.setBodyType(bodyType);
127
+ }
128
+ }
129
+ ```
130
+ healthCheckResult.java
131
+ ```ここに言語を入力
132
+ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
133
+ <%@ page import="model.Health" %>
134
+ <%
135
+ // リクエストスコープに保存されたHealthを取得
136
+ Health health = (Health) request.getAttribute("health");
137
+ %>
138
+ <!DOCTYPE html>
139
+ <html>
140
+ <head>
141
+ <meta charset="UTF-8">
142
+ <title>スッキリ健康診断</title>
143
+ </head>
144
+ <body>
145
+ <h1>スッキリ健康診断の結果</h1>
146
+ <p>
147
+ 身長:<%= health.getHeight() %><br>
148
+ 体重:<%= health.getWeight() %><br>
149
+ BMI:<%= health.getBmi() %><br>
150
+ 体格:<%= health.getBodyType() %>
151
+ </p>
152
+ <a href="/HealthCheck">戻る</a>
153
+ </body>
154
+ </html>
155
+ ```

1

ああああああ

2020/05/25 08:31

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- Javaのブレット「The origin server did not find a current representation for the target resource or is n
1
+ Javaのエラについてす。高校の授業で。
body CHANGED
@@ -1,181 +1,4 @@
1
1
  以下のコードを実行すると
2
- 「 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.」
3
2
  というエラーが発生します。
4
3
  おそらく、どこかのパスが違う気がするのですが、全くわかりません。
5
- どこが違うのかご教授お願いします。
4
+ どこが違うのかご教授お願いします。
6
-
7
- ディレクトリ
8
- ![イメージ説明](54d2ab35b2b1c47f7baba8e07d2b2a9d.png)
9
-
10
- Health.java
11
- ```ここに言語を入力
12
- package model;
13
-
14
- import java.io.Serializable;
15
-
16
- public class Health implements Serializable {
17
- private double height, weight, bmi;
18
- private String bodyType;
19
-
20
- public double getHeight() {
21
- return height;
22
- }
23
-
24
- public void setHeight(Double height) {
25
- this.height = height;
26
- }
27
-
28
- public double getWeight() {
29
- return weight;
30
- }
31
-
32
- public void setWeight(Double weight) {
33
- this.weight = weight;
34
- }
35
-
36
- public void setBmi(Double bmi) {
37
- this.bmi = bmi;
38
- }
39
-
40
- public double getBmi() {
41
- return this.bmi;
42
- }
43
-
44
- public void setBodyType(String bodyType) {
45
- this.bodyType = bodyType;
46
- }
47
-
48
- public String getBodyType() {
49
- return this.bodyType;
50
- }
51
- }
52
- ```
53
- healthCheck.java
54
- ```ここに言語を入力
55
- package servlet;
56
-
57
- import java.io.IOException;
58
-
59
- import javax.servlet.RequestDispatcher;
60
- import javax.servlet.ServletException;
61
- import javax.servlet.annotation.WebServlet;
62
- import javax.servlet.http.HttpServlet;
63
- import javax.servlet.http.HttpServletRequest;
64
- import javax.servlet.http.HttpServletResponse;
65
-
66
- import model.Health;
67
- import model.HealthCheckLogic;
68
-
69
- @WebServlet("/healthCheck")
70
- public class HealthCheck extends HttpServlet {
71
- private static final long serialVersionUID = 1L;
72
-
73
- protected void doGet(HttpServletRequest request,
74
- HttpServletResponse response)
75
- throws ServletException, IOException {
76
-
77
- // フォワード
78
- RequestDispatcher dispatcher =
79
- request.getRequestDispatcher
80
- ("/WEB-INF/jsp/healthCheck.jsp");
81
- dispatcher.forward(request, response);
82
- }
83
-
84
- protected void doPost(HttpServletRequest request,
85
- HttpServletResponse response)
86
- throws ServletException, IOException {
87
-
88
- // リクエストパラメータを取得
89
- String weight = request.getParameter("weight"); // 体重
90
- String height = request.getParameter("height"); // 身長
91
-
92
- // 入力値をプロパティに設定
93
- Health health = new Health();
94
- health.setHeight(Double.parseDouble(height));
95
- health.setWeight(Double.parseDouble(weight));
96
- // 健康診断を実行し結果を設定
97
- HealthCheckLogic healthCheckLogic = new HealthCheckLogic();
98
- healthCheckLogic.execute(health);
99
-
100
- // リクエストスコープに保存
101
- request.setAttribute("health", health);
102
-
103
- // フォワード
104
- RequestDispatcher dispatcher =
105
- request.getRequestDispatcher
106
- ("/jsp/healthCheckResult.jsp");
107
- dispatcher.forward(request, response);
108
- }
109
- }
110
-
111
- ```
112
- healthCheck.jsp
113
- ```ここに言語を入力
114
- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
115
- <!DOCTYPE html>
116
- <html>
117
- <head>
118
- <meta charset="UTF-8">
119
- <title>スッキリ健康診断</title>
120
- </head>
121
- <body>
122
- <h1>スッキリ健康診断</h1>
123
- <form action= "HealthCheck" method="post">
124
- 身長:<input type="text" name="height">(cm)<br>
125
- 体重:<input type="text" name="weight">(kg)<br>
126
- <input type="submit" value="診断">
127
- </form>
128
- </body>
129
- </html>
130
- ```
131
- HealthCheckLogic.java
132
- ```ここに言語を入力
133
- package model;
134
-
135
- public class HealthCheckLogic {
136
- public void execute(Health health) {
137
- // BMIを算出して設定
138
- double weight = health.getWeight();
139
- double height = health.getHeight();
140
- double bmi = weight / (height / 100.0 * height / 100.0);
141
- health.setBmi(bmi);
142
-
143
- // BMI指数から体格を判定して設定
144
- String bodyType;
145
- if (bmi < 18.5) {
146
- bodyType = "痩せ型";
147
- } else if (bmi < 25) {
148
- bodyType = "普通";
149
- } else {
150
- bodyType = "肥満";
151
- }
152
- health.setBodyType(bodyType);
153
- }
154
- }
155
- ```
156
- healthCheckResult.java
157
- ```ここに言語を入力
158
- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
159
- <%@ page import="model.Health" %>
160
- <%
161
- // リクエストスコープに保存されたHealthを取得
162
- Health health = (Health) request.getAttribute("health");
163
- %>
164
- <!DOCTYPE html>
165
- <html>
166
- <head>
167
- <meta charset="UTF-8">
168
- <title>スッキリ健康診断</title>
169
- </head>
170
- <body>
171
- <h1>スッキリ健康診断の結果</h1>
172
- <p>
173
- 身長:<%= health.getHeight() %><br>
174
- 体重:<%= health.getWeight() %><br>
175
- BMI:<%= health.getBmi() %><br>
176
- 体格:<%= health.getBodyType() %>
177
- </p>
178
- <a href="/HealthCheck">戻る</a>
179
- </body>
180
- </html>
181
- ```