开发者

Resource Bundle Spring

How can I access the messages from a resource bundle in Spring MVC inside a class that extends from AbstractController?

I have tried getMessageSourceAccessor().getMessage("a.message"); but it it throws this Exception:

开发者_Python百科

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.context.NoSuchMessageException: No message found under code 'a.message' for locale 'en'.

When I do the same inside a jsp it works

<spring:message code="a.message"/>


You can use one of the getMessage() method variants on the org.springframework.web.servlet.support.RequestContext class. Something like this works:

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    RequestContext ctx = new RequestContext(request);
    String messageFromBundle = ctx.getMessage("a.message");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜