File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Compilation Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Compilation Error" Watch "Compilation Error" New topic
Author

Compilation Error

Ravissant Markenday
Ranch Hand

Joined: Nov 12, 2006
Posts: 47
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Nov 16, 2005
Posts: 502

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).


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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&#41;" 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)


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ravissant Markenday
Ranch Hand

Joined: Nov 12, 2006
Posts: 47
Thanks Cameron, Prabhu and Ben !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation Error