简体   繁体   中英

How to restrict client IP address in Java Web Application

我需要基于客户端IP地址来限制视图,我有静态IP地址列表,并且只想向那些在我的Java Web应用程序中注册了IP地址的用户显示视图

Depends upon how you want to achieve the filtering.

  1. You can use a filter, which will validate and only then forward the request to the Servlet
  2. In the Servlet / Controller, you can write a check to control the redirection to a valid JSP or an error JSP
  3. Load the list in the servlet context and use that to check whether or not to show the content in JSP.

If I were you, I would use a filter, that way you are not even touching the Servlet layer with that IP.

See this link to know about Servlet Filters - http://docs.oracle.com/javaee/6/tutorial/doc/bnagb.html

It depends on what you would like to do.

Among other things you can filter out (restrict) the view of your applications to certain IPs only by configuring the server.

How to do it depends on the server.

For example for Tomcat you would need to edit the org.apache.catalina.valves.RemoteAddrValve in the context (filename: context.xml ). See also: http://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Remote_Address_Filter

  • The advantage of this method is that you completely isolate the application development from the IP filtering. And that you can apply the filtering to multiple applications.
  • The disadvantage would be that it is less flexible and less customizable than an application based solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM