怎样用servlet监听tomcat中客户端IP,并存入Mysql
怎样用servlet监听tomcat中客户端IP,并存入Mysql,电脑配置tomcat+mysql+jsp...
怎样用servlet监听tomcat中客户端IP,并存入Mysql,电脑配置 tomcat+mysql+jsp
展开
2个回答
展开全部
直接用filter监听
public class MyFilter extends HttpServlet implements Filter
然后在web.xml中配置:
<filter>
<filter-name>myfilter</filter-name>
<filter-class>com.fiter.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myfilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>myfilter</filter-name>
<url-pattern>/servlet/*</url-pattern>
</filter-mapping>
public class MyFilter extends HttpServlet implements Filter
然后在web.xml中配置:
<filter>
<filter-name>myfilter</filter-name>
<filter-class>com.fiter.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myfilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>myfilter</filter-name>
<url-pattern>/servlet/*</url-pattern>
</filter-mapping>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询