让我说我想从http上下文中检索一些信息。在我的百里香页中,我使用诸如此类的东西:
<span th:text="${#httpServletRequest.getHeader('Accept-Language')}"></span>
但是,在我的百里香叶处理器中,我使用了如下代码:
String language = arguments.getContext().getLocale().getLanguage();
String country = arguments.getContext().getLocale().getCountry();
如何通过以下方式在我的弹簧控制器中检索相同的信息?
@RequestMapping("/insert_texto/{page}")
public ModelAndView insert_texto(Model model, @PathVariable("page") String id) {
...
}
我将在您的控制器中直接注释servlet请求或上下文:
@Autowired
ServletContext context;
@RequestMapping("/insert_texto/{page}")
public ModelAndView insert_texto(Model model, @PathVariable("page") String id)
{
// use context
}
或者,如果愿意,ServletContext
可以将变量作为变量传递给您的方法:
@RequestMapping("/insert_texto/{page}")
public ModelAndView insert_texto(Model model, @PathVariable("page") String id, ServletContext context)
{
// use context
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句