users@glassfish.java.net

Re: NetBeans, Glassfish, J2EE Apllication.... I have a problem

From: Bobby Bissett <bobby.bissett_at_oracle.com>
Date: Mon, 7 Jun 2010 12:19:47 -0400

> [b]SERVLET[/b]
>
> public class CreaUtenteServ extends HttpServlet {
> protected void processRequest(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
> try{
> Utente u=new Utente();
> String id=request.getParameter("id");
> String nome=request.getParameter("nome");
> u.setId(id);
> u.setNome(nome);
>
> gestore.NewSessionBean cr=new gestore.NewSessionBean();
> cr.Creazione(u);
>
> }catch(Exception ex) {
> throw new ServletException(ex);
> } }

You can't use the constructor of the session bean in this case. That
will just give you an instance of the class but it won't be managed by
the container. Instead, try having the session bean injected into your
servlet. Something like:

@EJB
private NewSessionBean bean;

Then in the processRequest() method you can use the bean.

Cheers,
Bobby