質問編集履歴
4
社名が入っていたため修正。。
test
CHANGED
File without changes
|
test
CHANGED
@@ -614,7 +614,7 @@
|
|
614
614
|
|
615
615
|
/*
|
616
616
|
|
617
|
-
pw = new jp.co.
|
617
|
+
pw = new jp.co.xxx.wes.driver.PrintWriterWrapper(pw, strPage,
|
618
618
|
|
619
619
|
"htmllog.txt");
|
620
620
|
|
3
Servlet側でgetWriterを呼び出している箇所がありましたので追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -541,3 +541,89 @@
|
|
541
541
|
}
|
542
542
|
|
543
543
|
```
|
544
|
+
|
545
|
+
```Java
|
546
|
+
|
547
|
+
//Servlet側で実行しているメソッド
|
548
|
+
|
549
|
+
private static MaskingWriter getWriter(HttpServletRequest req,
|
550
|
+
|
551
|
+
HttpServletResponse resp,
|
552
|
+
|
553
|
+
ResourceBundle res,
|
554
|
+
|
555
|
+
String strPage)
|
556
|
+
|
557
|
+
throws java.io.IOException {
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
MaskingWriter pw;
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
if (isUseHtmlCompress(req, res)) {
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
String strHtmlCompressEncode = ResourceManager.getHtmlCompressEncode(null);
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
OutputStream out = resp.getOutputStream();
|
574
|
+
|
575
|
+
GZIPOutputStream gzipOut = new GZIPOutputStream(out);
|
576
|
+
|
577
|
+
OutputStreamWriter writer = null;
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
try {
|
582
|
+
|
583
|
+
writer = new OutputStreamWriter(gzipOut,strHtmlCompressEncode);
|
584
|
+
|
585
|
+
} catch (java.io.UnsupportedEncodingException e){
|
586
|
+
|
587
|
+
e.printStackTrace();
|
588
|
+
|
589
|
+
writer = new OutputStreamWriter(gzipOut, "SJIS");
|
590
|
+
|
591
|
+
}
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
PrintWriter tPW = new PrintWriter(writer,false);
|
596
|
+
|
597
|
+
pw = new MaskingWriter(tPW);
|
598
|
+
|
599
|
+
resp.setHeader("Content-Encoding","gzip");
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
}else{
|
604
|
+
|
605
|
+
PrintWriter tPW = resp.getWriter();
|
606
|
+
|
607
|
+
pw = new MaskingWriter(tPW);
|
608
|
+
|
609
|
+
}
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
// HTML をファイル出力するときには、以下の行を有効にする
|
614
|
+
|
615
|
+
/*
|
616
|
+
|
617
|
+
pw = new jp.co.softbrain.wes.driver.PrintWriterWrapper(pw, strPage,
|
618
|
+
|
619
|
+
"htmllog.txt");
|
620
|
+
|
621
|
+
*/
|
622
|
+
|
623
|
+
return pw;
|
624
|
+
|
625
|
+
}
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
```
|
2
遅くなりまして申し訳ありません。AjaxUrlMappingのimport部分の追記と、AjaxPageのコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -162,6 +162,22 @@
|
|
162
162
|
|
163
163
|
// ajaxから呼び出されるクラス
|
164
164
|
|
165
|
+
import java.util.List;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
import javax.servlet.http.HttpServletRequest;
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
import jp.co.xxx.wes.ajax.portal.MonthryReportServices;
|
174
|
+
|
175
|
+
import jp.co.xxx.wes.com.ConnectionPool;
|
176
|
+
|
177
|
+
import jp.co.xxx.wes.com.HtmlPage;
|
178
|
+
|
179
|
+
import jp.co.xxx.wes.sfa.document.DocumentInfoPage;
|
180
|
+
|
165
181
|
public class AjaxUrlMapping extends AjaxPage{
|
166
182
|
|
167
183
|
|
@@ -212,6 +228,132 @@
|
|
212
228
|
|
213
229
|
```Java
|
214
230
|
|
231
|
+
// Ajax Page
|
232
|
+
|
233
|
+
package jp.co.xxx.wes.ajax;
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
import jp.co.xxx.wes.com.HtmlPage;
|
238
|
+
|
239
|
+
import jp.co.xxx.wes.sfa.security.MaskingWriter;
|
240
|
+
|
241
|
+
public abstract class AjaxPage extends HtmlPage{
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
/** Ajax使用時にログイン状態を判定する */
|
246
|
+
|
247
|
+
public static final String PARAM_ISNOT_LOGIN_AJAX_ALLOW = "isNotLoginAjaxAllow";
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
private Exception exception;
|
252
|
+
|
253
|
+
private HtmlPage page_;
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
protected String ajaxUrl;
|
258
|
+
|
259
|
+
protected String serviceUrl;
|
260
|
+
|
261
|
+
protected String methodUrl;
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
public void print(MaskingWriter pw) throws Exception{
|
266
|
+
|
267
|
+
if(exception != null){
|
268
|
+
|
269
|
+
this.printError(pw);
|
270
|
+
|
271
|
+
}else{
|
272
|
+
|
273
|
+
if(page_ != null){
|
274
|
+
|
275
|
+
page_.print(pw);
|
276
|
+
|
277
|
+
}else{
|
278
|
+
|
279
|
+
pw.println("success");
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
public abstract void mapping() throws Exception;
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
private void printError(MaskingWriter pw){
|
294
|
+
|
295
|
+
exception.printStackTrace();
|
296
|
+
|
297
|
+
StackTraceElement[] stackTraceArray = exception.getStackTrace();
|
298
|
+
|
299
|
+
for(StackTraceElement stackTrace : stackTraceArray){
|
300
|
+
|
301
|
+
pw.println(stackTrace);
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
public void createUrl(){
|
310
|
+
|
311
|
+
String requestUrl = req_.getRequestURI();
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
ajaxUrl = requestUrl.split("/ajax/")[1];
|
316
|
+
|
317
|
+
serviceUrl = ajaxUrl.split("/")[0];
|
318
|
+
|
319
|
+
methodUrl = ajaxUrl.split("/")[1];
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
public void setException(Exception e){
|
326
|
+
|
327
|
+
exception = e;
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
public void setPage(HtmlPage page){
|
332
|
+
|
333
|
+
page_ = page;
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
public HtmlPage getPage(){
|
340
|
+
|
341
|
+
return page_;
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
```Java
|
356
|
+
|
215
357
|
public class MonthryReportServices extends AjaxUrlMapping {
|
216
358
|
|
217
359
|
|
1
情報が断片的との事でしたので、できる限り修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
画面からボタンを押したときにajax通信でJava側の処理を呼び出して
|
8
|
+
|
7
|
-
|
9
|
+
ファイルをダウンロードする処理を実装しているのですが、
|
8
|
-
|
10
|
+
|
9
|
-
resp_.getOutputStream();を実行したときに下記例外が発生してしまいます。
|
11
|
+
「resp_.getOutputStream();」を実行したときに下記例外が発生してしまいます。
|
10
12
|
|
11
13
|
> java.lang.IllegalStateException: getWriter()はこのレスポンスに対して既に呼び出されています
|
12
14
|
|
@@ -22,12 +24,16 @@
|
|
22
24
|
|
23
25
|
例外発生行の直前で「res.getWriter().close();」を入れても、今度はその行で同様の例外が発生するようでした。
|
24
26
|
|
27
|
+
※res:HttpServletResponseの変数
|
28
|
+
|
25
29
|
|
26
30
|
|
27
31
|
リソースを解放する方法についてご教示いただけないでしょうか。
|
28
32
|
|
29
33
|
|
30
34
|
|
35
|
+
Java8、Tomcat7です。
|
36
|
+
|
31
37
|
|
32
38
|
|
33
39
|
【参考にした記事】
|
@@ -44,8 +50,224 @@
|
|
44
50
|
|
45
51
|
|
46
52
|
|
53
|
+
```javascript
|
54
|
+
|
55
|
+
$(document).ready(function(){
|
56
|
+
|
57
|
+
$('#monthry_report_result_10051').on('click', function(){
|
58
|
+
|
59
|
+
var ajaxUrl = '/<コンテキスト名>/xxx/ajax/MonthryReportServices/printMonthryReport';
|
60
|
+
|
61
|
+
var param = { code : 10051, title : 'リスト' };
|
62
|
+
|
63
|
+
var callbackFunc = function(html){
|
64
|
+
|
65
|
+
if($(html).hasClass('error')){
|
66
|
+
|
67
|
+
$('.ajaxError').html($(html));
|
68
|
+
|
69
|
+
}else{
|
70
|
+
|
71
|
+
isDisabled = false;
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
ajaxFunc.ajax('post','html', ajaxUrl, param, callbackFunc);
|
78
|
+
|
79
|
+
});
|
80
|
+
|
81
|
+
});
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```javascript
|
90
|
+
|
91
|
+
/*非同期通信用*/
|
92
|
+
|
93
|
+
var ajaxFunc = {
|
94
|
+
|
95
|
+
ajax : function(type, dataType, url, data, successFunc, errorFunc, traditional, async){
|
96
|
+
|
97
|
+
if(traditional=="undefined") traditional = false;
|
98
|
+
|
99
|
+
if(async=="undefined") async = true;
|
100
|
+
|
101
|
+
var xhr = $.ajax({
|
102
|
+
|
103
|
+
type : type,
|
104
|
+
|
105
|
+
url : url,
|
106
|
+
|
107
|
+
data : data,
|
108
|
+
|
109
|
+
dataType : dataType,
|
110
|
+
|
111
|
+
cache : false,
|
112
|
+
|
113
|
+
timeout : 60000,
|
114
|
+
|
115
|
+
scriptCharset : "UTF-8",
|
116
|
+
|
117
|
+
traditional : traditional,
|
118
|
+
|
119
|
+
async : async,
|
120
|
+
|
121
|
+
success : function(data){
|
122
|
+
|
123
|
+
if(dataType=="json" && data!=null && eval(data).ajaxErrorCode!=null){
|
124
|
+
|
125
|
+
var setting = eval(data);
|
126
|
+
|
127
|
+
AjaxFunc.ajaxError(setting);
|
128
|
+
|
129
|
+
}else if((dataType=="" || dataType=="html" || dataType=="text") && data.match(/ajaxErrorCode/)!=null){
|
130
|
+
|
131
|
+
var setting = eval("("+data+")");
|
132
|
+
|
133
|
+
AjaxFunc.ajaxError(setting);
|
134
|
+
|
135
|
+
}else{
|
136
|
+
|
137
|
+
if (successFunc) {
|
138
|
+
|
139
|
+
if (typeof successFunc == 'string') {
|
140
|
+
|
141
|
+
eval(successFunc);
|
142
|
+
|
143
|
+
} else if (typeof successFunc == 'function') {
|
144
|
+
|
145
|
+
successFunc(data);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
|
160
|
+
|
47
161
|
```Java
|
48
162
|
|
163
|
+
// ajaxから呼び出されるクラス
|
164
|
+
|
165
|
+
public class AjaxUrlMapping extends AjaxPage{
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
public void mapping(){
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
/**
|
176
|
+
|
177
|
+
* URLから実行するServicesを特定する
|
178
|
+
|
179
|
+
*
|
180
|
+
|
181
|
+
* @param request HttpServletRequest
|
182
|
+
|
183
|
+
* @return
|
184
|
+
|
185
|
+
* @throws Exception
|
186
|
+
|
187
|
+
*/
|
188
|
+
|
189
|
+
public HtmlPage set(HttpServletRequest request) throws Exception{
|
190
|
+
|
191
|
+
String requestUrl = request.getRequestURI();
|
192
|
+
|
193
|
+
ajaxUrl = requestUrl.split("/ajax/")[1];
|
194
|
+
|
195
|
+
serviceUrl = ajaxUrl.split("/")[0];
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
if(serviceUrl.equals(MonthryReportServices.SERVICES_NAME)) {
|
200
|
+
|
201
|
+
return new MonthryReportServices();
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
```
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
```Java
|
214
|
+
|
215
|
+
public class MonthryReportServices extends AjaxUrlMapping {
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
public static final String SERVICES_NAME = "MonthryReportServices";
|
220
|
+
|
221
|
+
public static final String METHOD_PRINT_MONTHRY_REPORT = "printMonthryReport";
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
private static String portletTitle = "";
|
228
|
+
|
229
|
+
private static long portletCode = 0;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
private void init() {
|
234
|
+
|
235
|
+
portletTitle = req_.getParameter("portletTitle");
|
236
|
+
|
237
|
+
portletCode = Long.parseLong(req_.getParameter("portletCode"));
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
public void mapping() {
|
242
|
+
|
243
|
+
try {
|
244
|
+
|
245
|
+
init();
|
246
|
+
|
247
|
+
if(this.methodUrl.equals(METHOD_PRINT_MONTHRY_REPORT)){
|
248
|
+
|
249
|
+
try {
|
250
|
+
|
251
|
+
this.downloadReport();
|
252
|
+
|
253
|
+
} catch (Exception e) {
|
254
|
+
|
255
|
+
this.setPage(printError(e, AjaxErrorPage.AJAX_ERROR_CODE_FAILED_GET));
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
} catch (Exception e) {
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
49
271
|
public void downloadReport() throws Exception {
|
50
272
|
|
51
273
|
|
@@ -174,6 +396,6 @@
|
|
174
396
|
|
175
397
|
}
|
176
398
|
|
177
|
-
|
399
|
+
}
|
178
400
|
|
179
401
|
```
|