我正在从事 Spring MVC 控制器项目,在该项目中我正在从浏览器进行 GET URL 调用 -
下面是我从浏览器进行 GET 调用的 url -
http://127.0.0.1:8080/testweb/processing?workflow=test&conf=20140324&dc=all
下面是点击浏览器后调用的代码 -
@RequestMapping(value = "processing", method = RequestMethod.GET)
public @ResponseBody ProcessResponse processData(@RequestParam("workflow") final String workflow,
@RequestParam("conf") final String value, @RequestParam("dc") final String dc) {
System.out.println(workflow);
System.out.println(value);
System.out.println(dc);
// some other code
}
问题陈述:-
现在有什么办法,我可以从一些标头中提取 IP 地址吗?意思是我想知道来自哪个 IP 地址的呼叫来了,这意味着无论是谁在上面的 URL 上呼叫,我都需要知道他们的 IP 地址。这可能吗?
原文由 john 发布,翻译遵循 CC BY-SA 4.0 许可协议
解决办法是
将
HttpServletRequest request
添加到您的方法定义中,然后使用 Servlet APISpring Documentation 在这里 说