When users submit a form along with form data we can get the IP address of the client.
Let’s see one simple program to demonstrate this
request.getHeader(“X-FORWARDED-FOR”);
is used to get the address of client in java/jsp/struts and in spring.
1 2 3 4 5 6 7 8 9 10 11 | public class Post extends ActionSupport{ public String execute(){ HttpServletRequest request = ServletActionContext.getRequest(); String ipAdd = request.getHeader("X-FORWARDED-FOR"); if (ipAdd == null) { ipAdd = request.getRemoteAddr(); } System.out.pritln("Ip address of requested client is "+ipAdd); return SUCCESS; } } |