Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HttpSession.getAttribute not available to filter?

Status
Not open for further replies.

manarth

Programmer
Jul 2, 1999
1,705
GB
Code:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

		HttpServletResponse res = (HttpServletResponse)response;
		HttpServletRequest req = (HttpServletRequest)request;
		HttpSession ses = (HttpSession) req.getSession();
		[red]Object user = ses.getAttribute("user");[/red]

		if (user==null)
			try {
				res.sendRedirect("/login.jsp");
			} catch(IOException e) {
				e.printStackTrace();
			}
	}
Javac returns error:
cannot find symbol:[tt]
symbol : method getAttribute(java.lang.String)
location: interface javax.servlet.http.HttpSession
Object user = ses.getAttribute("user");[/tt]

It's obviously importing the HttpSession object, otherwise it would throw more errors. It's compiling with Tomcat's servlet-api.jar in the classpath.

<marc>
New to Tek-Tips? Get better answers - faq581-3339
 
Compiles OK for me ... I would guess that you have a servlet API in your CLASSPATH that is prior to version 2.2 .

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Ah, it appears that I had two competing servlet definitions:
- Tomcat's servlet-api.jar file (in my classpath)
- Sun JDK 1.5's javax.servlet.jar file (in JDK\jre\lib\ext).

I renamed the sun file to javax.servlet.jar.disabled; think I'll stick to the Tomcat implementation :)

<marc>
New to Tek-Tips? Get better answers - faq581-3339
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top