'기타' 카테고리의 다른 글
[MUDIS] MU-8H NEW웨이티드88건반 전자피아노 (0) | 2019.05.18 |
---|---|
SL-C433W 컬러레이저프린터 구매후기 (0) | 2018.12.13 |
저작권 표시 (0) | 2012.08.29 |
zip code 란 (0) | 2012.03.21 |
워드에서 티스토리 글 작성 (0) | 2012.03.11 |
[MUDIS] MU-8H NEW웨이티드88건반 전자피아노 (0) | 2019.05.18 |
---|---|
SL-C433W 컬러레이저프린터 구매후기 (0) | 2018.12.13 |
저작권 표시 (0) | 2012.08.29 |
zip code 란 (0) | 2012.03.21 |
워드에서 티스토리 글 작성 (0) | 2012.03.11 |
The fn:contains() function determines whether an input string contains a specified substring.
The fn:contains() function has following syntax:
boolean contains(java.lang.String, java.lang.String)
Following is the example to explain the functionality of this function:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <html> <head> <title>Using JSTL Functions</title> </head> <body> <c:set var="theString" value="I am a test String"/> <c:if test="${fn:contains(theString, 'test')}"> <p>Found test string<p> </c:if> <c:if test="${fn:contains(theString, 'TEST')}"> <p>Found TEST string<p> </c:if> </body> </html>
This would produce following result:
Found test string
source - http://www.tutorialspoint.com/jsp/jstl_function_contains.htm
reference - http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/tld-summary.html
boolean contains(java.lang.String, java.lang.String)
첫번째 매개변수 타입으로 ArrayList도 가능
servlet - 3.0 비동기 기능 (0) | 2013.07.27 |
---|---|
servlet - 필터(filter) (0) | 2013.07.27 |
jsp - 한글 파일명 다운로드 처리 (0) | 2013.07.22 |
jsp - 스마트폰 인식(모바일 기기 os 검출) (0) | 2013.06.01 |
jsp - response.sendRedirect와 request.getRequestDispatcher (0) | 2012.12.24 |
I'm using Spring MVC for a simple JSON API, with @ResponseBody
based approach like the following. (I already have a service layer producing JSON directly.)
@RequestMapping(value = "/matches/{matchId}", produces = "application/json")
@ResponseBody
public String match(@PathVariable String matchId) {
String json = matchService.getMatchJson(matchId);
if (json == null) {
// TODO: how to respond with e.g. 400 "bad request"?
}
return json;
}
Question is, in the given scenario, what is the simplest, cleanest way to respond with a HTTP 400 error?
I'm new to Spring MVC, and this turned out somewhat non-obvious... I did come across approaches like:
return new ResponseEntity(HttpStatus.BAD_REQUEST);
...but I can't use it here since my method's return type is String, not ResponseEntity.
change your return type to ResponseEntity<String>
, then you can use below for 400
return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
and for correct request
return new ResponseEntity<String>(json,HttpStatus.OK);
Something like this should work, I'm not sure whether or not there is a simpler way:
@RequestMapping(value = "/matches/{matchId}", produces = "application/json")
@ResponseBody
public String match(@PathVariable String matchId, @RequestBody String body,
HttpServletRequest request, HttpServletResponse response) {
String json = matchService.getMatchJson(matchId);
if (json == null) {
response.setStatus( HttpServletResponse.SC_BAD_REQUEST );
}
return json;
}
source - http://stackoverflow.com/questions/16232833/how-to-respond-with-http-400-error-in-a-spring-mvc-responsebody-method-returnin
spring data - redis example (0) | 2014.08.15 |
---|---|
spring - Get a file under WEB-INF using Spring(web-inf access) (0) | 2014.07.24 |
spring - velocity email(webmail in java) (0) | 2014.06.27 |
spring - Servlet 3 Async Config (0) | 2014.05.01 |
spring - spring mvc test (0) | 2014.04.17 |