获取网址中的在指定字段内容

String url="http://192.168.110.248:8080/dem_demo_war_exploded/enter.jsp"
int lastIndex=url.lastIndexOf("/");
int twoIndex=url.lastIndexOf("/");
System.out.println(url.substring(twoIndex+1,lastIndex));

过滤代码,如果是safedemo字段,则禁止访问使其退至login.jsp界面

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain)
HttpServletRequest httpServletRequest=(HttpServletRequest )servletRequest;
System.out.println(httpServletRequest.getRequestURL().toString);
String path=httpServletRequest.getRequestURL().toString();
int lastIndex=path.lastIndexOf("/");
int twoIndex=path.lastIndexOf("/",lastIndex-1);
String targetPath=path.substring(twoIndex+1,lastIndex);
HttpServletResponse httpServletResponse=(HttpServletResponse ) servletResponse;
if(targetPath.equals("safedemo")){
httpServletResponse.sendRedirect("/web_demo_war_exploded/login.jsp")
httpServletResponse.setCharacterEncoding(encoding);
System.out.println("before demoservlet........");
filterChain.doFilter(servletRequest,servletResponse);
System.out.println("after demoservlet.........");
}