回答編集履歴
1
再現について追記
test
CHANGED
@@ -26,6 +26,376 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
検証してみましが、`Mappingがうまくいかず、メソッドが呼び出せません。 `という状況が再現できませんでした。
|
30
|
+
|
31
|
+
再現に使用したソースは以下の通りとなります
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
JDK8 u77
|
36
|
+
|
37
|
+
Eclipse 4.5 mars2
|
38
|
+
|
39
|
+
Tomcat 8.0.33 with log4j1.2
|
40
|
+
|
41
|
+
spring-webmvc 4.2.5.RELEASE
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
TestController.java
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```java
|
50
|
+
|
51
|
+
package sandbox.slp.mvc;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
import java.text.ParseException;
|
56
|
+
|
57
|
+
import java.util.Arrays;
|
58
|
+
|
59
|
+
import java.util.List;
|
60
|
+
|
61
|
+
import java.util.Map;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
import javax.servlet.http.HttpServletRequest;
|
66
|
+
|
67
|
+
import javax.servlet.http.HttpServletResponse;
|
68
|
+
|
69
|
+
import javax.servlet.http.HttpSession;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
import org.slf4j.Logger;
|
74
|
+
|
75
|
+
import org.slf4j.LoggerFactory;
|
76
|
+
|
77
|
+
import org.springframework.stereotype.Controller;
|
78
|
+
|
79
|
+
import org.springframework.web.bind.annotation.RequestBody;
|
80
|
+
|
81
|
+
import org.springframework.web.bind.annotation.RequestMapping;
|
82
|
+
|
83
|
+
import org.springframework.web.bind.annotation.RequestMethod;
|
84
|
+
|
85
|
+
import org.springframework.web.bind.annotation.ResponseBody;
|
86
|
+
|
87
|
+
import org.springframework.web.bind.support.SessionStatus;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
import com.fasterxml.jackson.core.JsonProcessingException;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
@Controller
|
96
|
+
|
97
|
+
public class TestController {
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
private static final Logger log = LoggerFactory.getLogger(TestController.class);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
@RequestMapping(value = "/test/1", produces = "application/json;charset=UTF-8")
|
106
|
+
|
107
|
+
@ResponseBody
|
108
|
+
|
109
|
+
public String child_kensaku(@RequestBody String inputdata, HttpServletRequest request, HttpServletResponse response,
|
110
|
+
|
111
|
+
HttpSession session, SessionStatus sessionstatus)
|
112
|
+
|
113
|
+
throws IllegalArgumentException, IllegalAccessException, ParseException, JsonProcessingException {
|
114
|
+
|
115
|
+
log.info(inputdata);
|
116
|
+
|
117
|
+
return "{ \"name\":\"日本語\"}";
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
index.html
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```html
|
130
|
+
|
131
|
+
<!DOCTYPE html>
|
132
|
+
|
133
|
+
<html>
|
134
|
+
|
135
|
+
<head>
|
136
|
+
|
137
|
+
<title>jQuery ajax POST sample</title>
|
138
|
+
|
139
|
+
<script
|
140
|
+
|
141
|
+
src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
|
142
|
+
|
143
|
+
<script>
|
144
|
+
|
145
|
+
$(function() {
|
146
|
+
|
147
|
+
$("#ajax_btn").click(function ajaxpost() {
|
148
|
+
|
149
|
+
var formData = {
|
150
|
+
|
151
|
+
name : "日本語文字列入お名前",
|
152
|
+
|
153
|
+
age : "31"
|
154
|
+
|
155
|
+
};
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
$.ajax({
|
160
|
+
|
161
|
+
url : "test/1/",
|
162
|
+
|
163
|
+
type : "POST",
|
164
|
+
|
165
|
+
data : JSON.stringify(formData),
|
166
|
+
|
167
|
+
contentType : 'application/json;charset=UTF-8', // リクエストの Content-Type
|
168
|
+
|
169
|
+
dataType : "json", // レスポンスをJSONとしてパースする
|
170
|
+
|
171
|
+
success : function(data, textStatus, jqXHR) {
|
172
|
+
|
173
|
+
//data - response from server
|
174
|
+
|
175
|
+
console.log(data);
|
176
|
+
|
177
|
+
},
|
178
|
+
|
179
|
+
error : function(jqXHR, textStatus, errorThrown) {
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
});
|
186
|
+
|
187
|
+
});
|
188
|
+
|
189
|
+
});
|
190
|
+
|
191
|
+
</script>
|
192
|
+
|
193
|
+
</head>
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
<body>
|
198
|
+
|
199
|
+
<input id="ajax_btn" type="button" value="1押す" />
|
200
|
+
|
201
|
+
</body>
|
202
|
+
|
203
|
+
</html>
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
servlet-context.xml
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
```xml
|
212
|
+
|
213
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
214
|
+
|
215
|
+
<beans:beans
|
216
|
+
|
217
|
+
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
218
|
+
|
219
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
220
|
+
|
221
|
+
xmlns:beans="http://www.springframework.org/schema/beans"
|
222
|
+
|
223
|
+
xmlns:context="http://www.springframework.org/schema/context"
|
224
|
+
|
225
|
+
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
|
226
|
+
|
227
|
+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
228
|
+
|
229
|
+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
230
|
+
|
231
|
+
<mvc:annotation-driven />
|
232
|
+
|
233
|
+
<mvc:resources
|
234
|
+
|
235
|
+
mapping="/resources/**"
|
236
|
+
|
237
|
+
location="/resources/" />
|
238
|
+
|
239
|
+
<mvc:resources
|
240
|
+
|
241
|
+
mapping="/*"
|
242
|
+
|
243
|
+
location="/" />
|
244
|
+
|
245
|
+
</beans:beans>
|
246
|
+
|
247
|
+
```
|
248
|
+
|
249
|
+
pom.xml
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```xml
|
254
|
+
|
255
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
256
|
+
|
257
|
+
<project
|
258
|
+
|
259
|
+
xmlns="http://maven.apache.org/POM/4.0.0"
|
260
|
+
|
261
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
262
|
+
|
263
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
264
|
+
|
265
|
+
<modelVersion>4.0.0</modelVersion>
|
266
|
+
|
267
|
+
<groupId>sandbox</groupId>
|
268
|
+
|
269
|
+
<artifactId>sandbox.slp</artifactId>
|
270
|
+
|
271
|
+
<name>sandbox.slp</name>
|
272
|
+
|
273
|
+
<packaging>war</packaging>
|
274
|
+
|
275
|
+
<version>1.0.0-BUILD-SNAPSHOT</version>
|
276
|
+
|
277
|
+
<properties>
|
278
|
+
|
279
|
+
<org.springframework-version>4.2.5.RELEASE</org.springframework-version>
|
280
|
+
|
281
|
+
</properties>
|
282
|
+
|
283
|
+
<dependencies>
|
284
|
+
|
285
|
+
<!-- Spring -->
|
286
|
+
|
287
|
+
<dependency>
|
288
|
+
|
289
|
+
<groupId>org.springframework</groupId>
|
290
|
+
|
291
|
+
<artifactId>spring-webmvc</artifactId>
|
292
|
+
|
293
|
+
<version>${org.springframework-version}</version>
|
294
|
+
|
295
|
+
</dependency>
|
296
|
+
|
297
|
+
<dependency>
|
298
|
+
|
299
|
+
<groupId>ch.qos.logback</groupId>
|
300
|
+
|
301
|
+
<artifactId>logback-classic</artifactId>
|
302
|
+
|
303
|
+
<version>1.1.7</version>
|
304
|
+
|
305
|
+
</dependency>
|
306
|
+
|
307
|
+
<dependency>
|
308
|
+
|
309
|
+
<groupId>javax.servlet</groupId>
|
310
|
+
|
311
|
+
<artifactId>javax.servlet-api</artifactId>
|
312
|
+
|
313
|
+
<version>3.1.0</version>
|
314
|
+
|
315
|
+
<scope>provided</scope>
|
316
|
+
|
317
|
+
</dependency>
|
318
|
+
|
319
|
+
<dependency>
|
320
|
+
|
321
|
+
<groupId>javax.servlet.jsp</groupId>
|
322
|
+
|
323
|
+
<artifactId>javax.servlet.jsp-api</artifactId>
|
324
|
+
|
325
|
+
<version>2.3.1</version>
|
326
|
+
|
327
|
+
<scope>provided</scope>
|
328
|
+
|
329
|
+
</dependency>
|
330
|
+
|
331
|
+
<dependency>
|
332
|
+
|
333
|
+
<groupId>javax.servlet</groupId>
|
334
|
+
|
335
|
+
<artifactId>jstl</artifactId>
|
336
|
+
|
337
|
+
<version>1.2</version>
|
338
|
+
|
339
|
+
</dependency>
|
340
|
+
|
341
|
+
<dependency>
|
342
|
+
|
343
|
+
<groupId>com.fasterxml.jackson.core</groupId>
|
344
|
+
|
345
|
+
<artifactId>jackson-databind</artifactId>
|
346
|
+
|
347
|
+
<version>2.7.3</version>
|
348
|
+
|
349
|
+
</dependency>
|
350
|
+
|
351
|
+
<dependency>
|
352
|
+
|
353
|
+
<groupId>com.fasterxml.jackson.core</groupId>
|
354
|
+
|
355
|
+
<artifactId>jackson-core</artifactId>
|
356
|
+
|
357
|
+
<version>2.7.3</version>
|
358
|
+
|
359
|
+
</dependency>
|
360
|
+
|
361
|
+
<dependency>
|
362
|
+
|
363
|
+
<groupId>com.fasterxml.jackson.core</groupId>
|
364
|
+
|
365
|
+
<artifactId>jackson-annotations</artifactId>
|
366
|
+
|
367
|
+
<version>2.7.3</version>
|
368
|
+
|
369
|
+
</dependency>
|
370
|
+
|
371
|
+
</dependencies>
|
372
|
+
|
373
|
+
</project>
|
374
|
+
|
375
|
+
```
|
376
|
+
|
377
|
+
サーバ側でのログ出力
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
```
|
382
|
+
|
383
|
+
17:52:49.271 [http-nio-8080-exec-25] INFO sandbox.slp.mvc.TestController - {"name":"日本語文字列入お名前","age":"31"}
|
384
|
+
|
385
|
+
```
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
クライアント側でのログ出力
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
```
|
394
|
+
|
395
|
+
Object {name: "日本語"}
|
396
|
+
|
397
|
+
```
|
398
|
+
|
29
399
|
また、以下の依存関係を追加し、オブジェクトのまま`jsonstr`を返却すれば`@RequestMapping(value = "/test")`のみで文字化けせずにJSONデータとして返却されるようになります。
|
30
400
|
|
31
401
|
|