2014-09-30 165 views

回答

3

在您的@Controller中注入ServletContext

@Autowired 
private ServletContext context; 

,並用它來獲取上下文參數

context.getInitParameter("param-name") 
0

您還可以使用參數HttpServletRequest的控制器方法。

public String getContextValue(HttpServletRequest httprequest) { 

     HttpSession htsession = httprequest.getSession(); 
      ServletContext servContext = htsession.getServletContext(); 
      String paramValue = (String)servContext.getInitParameter("paramName"); 
      return paramValue; 
     } 
0

爲3.0:

@Value("#{contextParameters.param-name}") 
private String paramName; 
相關問題