欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

struts2获得ip我这么弄得 博客分类: ssh  

程序员文章站 2024-03-19 15:49:34
...
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

import com.cms.Constant.WebConstant;

public class RequestListener implements ServletRequestListener {
	public void requestInitialized(ServletRequestEvent sre) {
		ServletRequest request = sre.getServletRequest();
		request.setAttribute(WebConstant.HOST, request.getRemoteHost());
	}

	public void requestDestroyed(ServletRequestEvent sre) {
	}
}

 然后再取出来 

	ActionContext ctx = ActionContext.getContext();
			Map request = (Map)ctx.get("request");
			System.out.println(request.get(WebConstant.HOST));

 麻烦啊