• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Problem

 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I know this topic is been discused here a lot . But i have an error thrown so thought if any one would help

I have a method where we set the session variable
public void update(Observable o, Object arg)
{

super.update(o,arg);
Datagrid m_newdatagrid1 = (Datagrid)getControl(CONTROL_GRID, Datagrid.class);
DataProvider dp = (DataProvider)m_newdatagrid1.getDataProvider();
getPageContext().getSession().setAttribute("dap",dp);

}

Now i am retreiving the session in other method in same class

public void writefile1(HttpServletResponse response, JspWriter out)throws IOException, DfException
DataProvider w_dp = null;

try
{
w_dp = (DataProvider) SessionState.getAttribute("dap");
}
catch (NullPointerException e )
{System.out.println("The Session is Not set" + e);
}

Q) IT THROWS ME NULL POINTER EXCEPTION

can someone help please
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj
Okay i have read your problem. You mean to say your setting some value in session and when u try to access it, you get null back. Okay is the code you have given in the forum in servlets/jsp/utility class. Morever what is "SessionState". can you provide more info so that i can help. Please give a small background of your requirement.

Regards
Makarand Parab
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj
One more thing, Just print
DataProvider dp = (DataProvider)m_newdatagrid1.getDataProvider();
System.out.println(dp);

check if ur getting some object before you are place it in session.


Regards
Makarand Parab
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Makarand

This piece of code is from a tool call Documentum which uses J@EE frame work

ANd yeh Dataprovider dp does return something i have tested it .
String rc1 = dp.getDataField(strAttr1);
System.out.println("the result in jsp page is :" + rc1);


and "SessionState" it is one of Documentum API which is similar to session in JSP.


we can say Dataprovider is like a reusltset ( which is produced when we run a query)

can we pass a resultset in a session variable ?
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj
Do one thing, instead of using SessionSate, put this line
getPageContext().getSession().getAttribute("dap");
and try.
Let me know what you are getting as output.

Yes you can put resultset in session, though it is not a good practice to do so. Anything that is a valid object can be staored in the session.


Regards
MAkarand Parab
 
payal agrawal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can look at this URL
http://www.java-tips.org/content/view/118/40/
 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Makarand,

I am extremely sorry for not getting back to you

yes it work :-)


Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic