質問編集履歴
1
500エラーが出力される部分のコードの追記 JOptionPaneについて
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,3 +29,145 @@
|
|
29
29
|
$ export CATALINA_OPTS="-Djava.awt.headless=true"
|
30
30
|
|
31
31
|
この一行を追記するということでしょうか?
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
以下エラーが発生したJavaサーブレットのコードになります。
|
36
|
+
|
37
|
+
```Java
|
38
|
+
|
39
|
+
package servlet;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
import java.io.IOException;
|
44
|
+
|
45
|
+
import java.util.List;
|
46
|
+
|
47
|
+
import java.util.Properties;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
import javax.servlet.ServletException;
|
52
|
+
|
53
|
+
import javax.servlet.annotation.WebServlet;
|
54
|
+
|
55
|
+
import javax.servlet.http.HttpServlet;
|
56
|
+
|
57
|
+
import javax.servlet.http.HttpServletRequest;
|
58
|
+
|
59
|
+
import javax.servlet.http.HttpServletResponse;
|
60
|
+
|
61
|
+
import javax.servlet.http.HttpSession;
|
62
|
+
|
63
|
+
import javax.swing.JFrame;
|
64
|
+
|
65
|
+
import javax.swing.JOptionPane;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
import model.HistoryDeleteLogic;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
@WebServlet("/HistoryDelete")
|
74
|
+
|
75
|
+
public class HistoryDelete extends HttpServlet {
|
76
|
+
|
77
|
+
private static final long serialVersionUID = 1L;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
82
|
+
|
83
|
+
HttpSession session = request.getSession(); // セッションを取得するための準備
|
84
|
+
|
85
|
+
int logId; // ログインIDを保存しておくための変数
|
86
|
+
|
87
|
+
StringBuffer urlBuffer = request.getRequestURL(); // 変数 urlBuffer に現在のページのURLを格納する(ただし、?以降のパラメータ情報は取得できない)
|
88
|
+
|
89
|
+
String url = urlBuffer.append("?").append(request.getQueryString()).toString(); // 先ほど取得したURL文字列の後ろに、現在のパラメータ情報をドッキングする
|
90
|
+
|
91
|
+
int indexOfParam = url.indexOf("="); // パラメータ付きURLかどうかを調べる(=マークがあるかどうか)
|
92
|
+
|
93
|
+
if(session.getAttribute("loginUser") != null && indexOfParam != -1) {
|
94
|
+
|
95
|
+
logId = Integer.parseInt(url.substring(indexOfParam + 1)); // =マークから先を切り取り、取得した文字列を変数 logId に格納する(int型へキャスト)
|
96
|
+
|
97
|
+
HistoryDeleteLogic hdl=new HistoryDeleteLogic();
|
98
|
+
|
99
|
+
List<Integer> list = hdl.act(logId);
|
100
|
+
|
101
|
+
int result;
|
102
|
+
|
103
|
+
JFrame frame = new JFrame();
|
104
|
+
|
105
|
+
Properties prop = System.getProperties ();
|
106
|
+
|
107
|
+
prop.put ("java.awt.headless", "false");
|
108
|
+
|
109
|
+
Object[] options = { "はい", "いいえ" };
|
110
|
+
|
111
|
+
frame.setAlwaysOnTop(true);
|
112
|
+
|
113
|
+
result = JOptionPane.showOptionDialog(frame, "削除してもよろしいですか?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
|
114
|
+
|
115
|
+
switch (result) {
|
116
|
+
|
117
|
+
case JOptionPane.OK_OPTION:
|
118
|
+
|
119
|
+
hdl.execute(logId);
|
120
|
+
|
121
|
+
JFrame frame2 = new JFrame();
|
122
|
+
|
123
|
+
Properties prop2 = System.getProperties ();
|
124
|
+
|
125
|
+
prop.put ("java.awt.headless", "false");
|
126
|
+
|
127
|
+
Object[] options2 = { "はい" };
|
128
|
+
|
129
|
+
frame2.setAlwaysOnTop(true);
|
130
|
+
|
131
|
+
JOptionPane.showOptionDialog(frame2, "削除しました", "Information", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options2, options2[0]);
|
132
|
+
|
133
|
+
case JOptionPane.NO_OPTION:
|
134
|
+
|
135
|
+
case JOptionPane.CANCEL_OPTION:
|
136
|
+
|
137
|
+
default:
|
138
|
+
|
139
|
+
session.setAttribute("year", list.get(0));
|
140
|
+
|
141
|
+
session.setAttribute("month", list.get(1));
|
142
|
+
|
143
|
+
session.setAttribute("weightHistoryLength", null);
|
144
|
+
|
145
|
+
response.sendRedirect("/bodyMassIndex/History");
|
146
|
+
|
147
|
+
break;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
else {
|
154
|
+
|
155
|
+
response.sendRedirect("/bodyMassIndex/");
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
上記コードのJFrame frame = new JFrame();の部分で、エラー画面が出力されているようです。
|
172
|
+
|
173
|
+
サーバのTomcatではJOptionPaneは使用できないのでしょうか?
|