• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stateful Session and JSP

 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Can someone give me an example of the best way to use a stateful session in a jsp. I need the statefull session to store the data that is on a form. I understand how to create the jsp and session bean, but I don't know the best way to tie the two together. Do you make direct calls from the jsp to the stateful session bean or do you just a javabean or is there another way?
Thanks,
Trish
 
monojit choudhury
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can access the session bean's business logic method via the remote interface.u can write the same way in jsp as u wud've written in a .java class file.
'm writing a simple example .jsp code which maintains the page count.
<%@ page language="java" import="javax.ejb.*,javax.naming.*,java.io.*,java.util.*,java.text.*" %>
<%<br /> <br /> int count=0;<br /> try<br /> {<br /> Properties prop=System.getProperties();<br /> prop.put(Context.INITIAL_CONTEXT_FACTORY,<br /> "weblogic.jndi.WLInitialContextFactory");<br /> Context ctx= new InitialContext(prop);<br /> StateFullHome home =(StateFullHome) ctx.lookup("MyStateFullHome");<br /> int i=1;<br /> StateFull home =home.create(i);<br /> >%
<HTML>
<BODY>
<H2>U have Entered this page <%home.count()%> number of times</H2>
</BODY>
</HTML>
<%<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> <br /> %>
 
monojit choudhury
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops sorry,the code seems to've left out somewhere.
well........here it is
< %@ page language="java" import="javax.ejb.*,javax.naming.*,java.io.*,java.util.*,java.text.*" %>
< %<br /> <br /> int count=0;<br /> try<br /> {<br /> Properties prop=System.getProperties();<br /> prop.put(Context.INITIAL_CONTEXT_FACTORY,<br /> "weblogic.jndi.WLInitialContextFactory");<br /> Context ctx= new InitialContext(prop);<br /> StateFullHome home =(StateFullHome) ctx.lookup("MyStateFullHome");<br /> int i=1;<br /> StateFull home =home.create(i);<br /> >%
< HTML >
< BODY >
< H2 >U have Entered this page < %home.count()%> number of times< /H2>
< /BODY>
< /HTML>
< %<br /> }<br /> catch(Exception e)<br /> {<br /> <br /> }<br /> <br /> %>

[This message has been edited by Thomas Paul (edited December 10, 2001).]
Fixed for formatting
[This message has been edited by Thomas Paul (edited December 10, 2001).]
 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks monojit choudhury I appreciate it. That helps!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!