我對Spring MVC的控制器項目的工作中,我提出來自瀏覽器的GET URL調用 -如何在Spring MVC Controller中提取IP地址獲取調用?
下面是由我提出來自瀏覽器的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地址。這可能嗎?
感謝Koitoer的幫助。一個簡單的問題,假設如果調用來自Load Balancer而不是特定的機器,那麼這也會起作用嗎?我猜不是.. – john
沒有它不會,但負載平衡器中有一些配置可以發送IP,因爲它們不存在,可能這是您的情況 – Koitoer
檢查可能負載平衡器可以將這些值發送到標題中,因此請考慮使用HttpServletRequest的getHeader方法。 – Koitoer