public class SprojServlet extends HttpServlet {
@EJB
private SprojRemote sprojBean;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
{
String name=request.getParameter("uname");
boolean b=sprojBean.chek(name);
if(b)
{
out.println(name+" is Authenticated to Proceed");
}
else
{
out.println("Sorry "+name +" you are not Authenticated to Proceed");
}
out.println("<br>");
out.println(sprojBean.returnMYName());
} finally {
out.close();
}
}
}
and the jsp Client
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<center>
<h2>
Stateless Bean Demo
<br>
<br>
<hr>
<br>
Enter User Name
<input type="text" name="uname">
<br>
<br>
<input type="Submit" value="Submit">
</h2>
</center>
</body>
</form>
</html>
This is working very good .
But to check the statelessness of the bean i added another web module SecondSproj and there a used another servlet "SecondSprojServlet.java" to call the same bean
Second servlet in Another Module (i am considering this as another client (if i am correct))
if i am giving name as Deepak at index.jsp it show at Servlet "SprojServlet.java " that "Deepak is Authenticated to Proceed"
after this if i run second servlet and call returnMyName()
it shows "Deepak"
but if the bean is stateless so it must return null
as it creates only one object for each client.
Please correct me where i am worng.
Thanking You
Constant dripping hollows out a stone....
Hong Anderson
Ranch Hand
Joined: Jul 05, 2005
Posts: 1936
posted
0
It doesn't "must" return null, but it "may" return null.
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Deepak Bobal
Ranch Hand
Joined: Feb 06, 2008
Posts: 96
posted
0
it's surprising
there are 32 active bean instances in pool
but while running 20 times it picks only the same instance
Hong Anderson
Ranch Hand
Joined: Jul 05, 2005
Posts: 1936
posted
0
Deepak Bobal wrote:
there are 32 active bean instances in pool
How do you that there are 32? Is it a maximum number?
You could write a client program to send many requests if you want to prove statelessness.
Deepak Bobal
Ranch Hand
Joined: Feb 06, 2008
Posts: 96
posted
0
i noticed 32 as max pool size under configuration of glass fish.
Hong Anderson
Ranch Hand
Joined: Jul 05, 2005
Posts: 1936
posted
0
Deepak Bobal wrote:i noticed 32 as max pool size under configuration of glass fish.
That is maximum number but there maybe only 1 instance if there are no much requests.
You could write a client program that sends many request to to server.
santosh patil
Greenhorn
Joined: May 14, 2008
Posts: 5
posted
0
For each request you are getting same bean from pool. While using stateless session bean one should ensure re-initialization of instance variables before returning bean to pool.