Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
Add links on 'Writing Responses' tab with response containing UTF-8 c…
Browse files Browse the repository at this point in the history
…haracters.
  • Loading branch information
rstoyanchev committed Sep 16, 2011
1 parent 18f744b commit 80ec02a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -17,6 +17,16 @@ public class ResponseController {
return "The String ResponseBody";
}

@RequestMapping(value="/response/charset/accept", method=RequestMethod.GET)
public @ResponseBody String responseAcceptHeaderCharset() {
return "こんにちは世界! (\"Hello world!\" in Japanese)";
}

@RequestMapping(value="/response/charset/produce", method=RequestMethod.GET, produces="text/plain;charset=UTF-8")
public @ResponseBody String responseProducesConditionCharset() {
return "こんにちは世界! (\"Hello world!\" in Japanese)";
}

@RequestMapping(value="/response/entity/status", method=RequestMethod.GET)
public ResponseEntity<String> responseEntityStatusCode() {
return new ResponseEntity<String>("The String ResponseBody with custom status code (403 Forbidden)",
Expand Down
14 changes: 13 additions & 1 deletion src/main/webapp/WEB-INF/views/home.jsp
Expand Up @@ -151,6 +151,12 @@
<li>
<a id="responseBody" class="textLink" href="<c:url value="/response/annotation" />">@ResponseBody</a>
</li>
<li>
<a id="responseCharsetAccept" class="utf8TextLink" href="<c:url value="/response/charset/accept" />">@ResponseBody (UTF-8 charset requested)</a>
</li>
<li>
<a id="responseCharsetProduce" class="textLink" href="<c:url value="/response/charset/produce" />">@ResponseBody (UTF-8 charset produced)</a>
</li>
<li>
<a id="responseEntityStatus" class="textLink" href="<c:url value="/response/entity/status" />">ResponseEntity (custom status)</a>
</li>
Expand Down Expand Up @@ -393,7 +399,13 @@ $(document).ready(function() {
$.ajax({ url: link.attr("href"), dataType: "text", success: function(text) { MvcUtil.showSuccessResponse(text, link); }, error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, link); }});
return false;
});
$("a.utf8TextLink").click(function(){
var link = $(this);
$.ajax({ url: link.attr("href"), dataType: "text", beforeSend: function(req) { req.setRequestHeader("Accept", "text/plain;charset=UTF-8"); }, success: function(text) { MvcUtil.showSuccessResponse(text, link); }, error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, link); }});
return false;
});
$("form.textForm").submit(function(event) {
var form = $(this);
var button = form.children(":first");
Expand Down

0 comments on commit 80ec02a

Please sign in to comment.