Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compilation Error

 
Ravissant Markenday
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone!

im getting this error while compiling a servlet:

SessionLifeCycleServlet.java:88: setAttribute(java.lang.String,java.lang.Object
in javax.servlet.http.HttpSession cannot be applied to (java.lang.String)
session.setAttribute(fname);
^

Could anyone please tell me what it means and what i can do to fix it?

Thanks in advance,
Ravissant Markenday
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're missing a parameter. You have to provide a name/value pair to the setAttribute method.

session.setAttribute("First Name", fname);

Here's a tutorial on using the HttpSession object, along with some sample code:

Free Tutorial on How to Use the HttpSession Object in a J2EE Application

Happy Java!

-Cameron McKenzie
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any setAttribute method will accept two parameters. both are of type Object.

But you are passing only one parameter. Make it two(both should of type Object).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prabhu Venkatachalam:
Any setAttribute method will accept two parameters. both are of type Object.

But you are passing only one parameter. Make it two(both should of type Object).


Not entirely true.
The setAttribute method does take two arguments but the first is java.lang.String.
See:
java.lang.String,%20java.lang.Object)" target="_blank" rel="nofollow">http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String,%20java.lang.Object)
 
Ravissant Markenday
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cameron, Prabhu and Ben !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic