kranthi adari wrote:In a servlet, you cannot use page-directive, Sorry. Please find my steps below to implement <jsp:usebean> equivalent in servlet.
Import the bean using import <bean-path>
and then create a session object
HttpSevletSession sesssion = request.getSession();
Now create a bean object
MyBean b = new MyBean();
set the data of the bean and then add to the session.
session.setAttribute("bean, b);
This makes the assumption that the variable does not already exist in the scope defined. The jsp:useBean first checks to see if the variable does not exist before making the new object. The most similar code would be:
That assumes the scope being looked at is the session, replace the intended scope as needed.