How to set a session in Java Filter?

I make a filter,in this filter,I check a request parameter,if this parameter equals a assigned name,I put a flag into a session,like follows:

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException

String name=request.getParameter("name");

.....

if(name.compareTo("John")==0){

session.setAttribute("isLogin","true");

}

...

}

But when I run above program,I will get a error,because session is not defined. I know HttpSession is get by HttpServletRequest.getSession(),

but public void doFilter is only provide ServletRequest,not HttpServletRequest! I want to know whether there is a method which I can get HttpSession in Filter?

Any idea will be appreciated!

[802 byte] By [EdwardKinga] at [2007-10-2 10:56:39]
# 1
Hi. You should be able to simply cast The ServletRequest like this:(HttpServletRequest)requestIf you run a webcontainer, you're pretty sure its a Http-request.
SomeThingWeirda at 2007-7-13 3:22:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...