Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 30th, 2006, 08:31 AM
Authorized User
Join Date: Jul 2003
Location: , , .
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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");

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 the 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!

Reply With Quote
  #2 (permalink)  
Old January 31st, 2006, 05:34 AM
Authorized User
Join Date: Jan 2006
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to longjava

What you need to do is casting it to HttpServletRequest as following:

String name = request.getParameter( "name" );
if ( name.compareTo( "John" ) )
   if ( request instanceof HttpServletRequest )
      httpRequest = (HttpServletRequest) request; // doing casting here
      httpRequest.setAttribute( "isLogin", "true" );

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set Session to FormView Label sterreyl ASP.NET 2.0 Basics 0 March 29th, 2007 11:16 AM
how to set session.save_path on WS 2003 ? cristi Pro PHP 2 April 2nd, 2005 04:45 PM
Re: need a correct method to set filter flyfish Access 2 January 28th, 2005 06:32 AM
set maximum session time through program vinodkalpaka Beginning PHP 1 December 17th, 2004 10:44 AM
How to set up Java AppServer partho_choudhury J2EE 7 June 14th, 2004 02:29 AM

All times are GMT -4. The time now is 07:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.