最近突然想到一个问题,怎么样通过程序来获取哪些网页被哪些蜘蛛来爬过?
不知道是否可以得到相应的信息?
------解决方案--------------------
request.getHeader
------解决方案--------------------
呵呵,这个贴还没结。。。。
给你答案:
先在web.xml中加这么几条
<filter>
<filter-name> FileFilter </filter-name>
<filter-class> com.abc.FileFilter </filter-class>
</filter>
<filter-mapping>
<filter-name> FileFilter </filter-name>
<url-pattern> /*.jsp </url-pattern>
</filter-mapping>
这是把所有的访问xxx.jsp的都先通过com.abc.FileFilter这个类,这样就好记录了
com.abc.FileFilter:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
public class FileFilter
implements Filter {
public void init(FilterConfig config) throws javax.servlet.ServletException {
}
private static Log log = LogFactory.getLog(FileFilter.class);
private StringBuffer sb;
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws java.io.IOException,
javax.servlet.ServletException {
HttpServletRequest hrequest = (HttpServletRequest) request;
sb = new StringBuffer();
String uri = hrequest.getServletPath();
uri = uri.toLowerCase();
String referer = request.getHeader( "referer ");
log.debug(referer);//=================这里记录访问记录等信息
if (uri.startsWith( "/list- ")) {//================这里是返回到你的页面,具体改一下
hrequest.getRequestDispatcher(sb.append( "/search.jsp?action=singer&keyword= ").append(uri.substring(8, uri.length()).replaceAll( ".jsp ", " ")).toString()).forward(request, response);
sb = null;
}
}
public void destroy() {
}
}
分不是问题,这只是个帐号,只是看你对这个问题的重视程度而已,所以上面我才说“才20分”。。。