View Javadoc
1   package ejava.examples.webtier.web;
2   
3   import java.io.IOException;
4   import java.io.PrintWriter;
5   
6   import javax.naming.InitialContext;
7   import javax.persistence.EntityManager;
8   import javax.persistence.PersistenceContext;
9   import javax.servlet.ServletException;
10  import javax.servlet.http.HttpServlet;
11  import javax.servlet.http.HttpServletRequest;
12  import javax.servlet.http.HttpServletResponse;
13  
14  import org.slf4j.Logger;
15  import org.slf4j.LoggerFactory;
16  
17  import ejava.util.jndi.JNDIUtil;
18  
19  @SuppressWarnings("serial")
20  public class JPADAOInit extends HttpServlet {
21      private Logger logger = LoggerFactory.getLogger(JPADAOInit.class);
22      
23      @PersistenceContext(unitName="webtier")
24      private EntityManager em;
25      
26      protected void doGet(HttpServletRequest request, 
27                           HttpServletResponse response) 
28          throws ServletException, IOException {
29          
30          StringBuilder text = new StringBuilder();
31          try {
32              InitialContext jndi = new InitialContext();
33              logger.debug(new JNDIUtil().dump(jndi,""));
34              logger.debug(new JNDIUtil().dump(jndi,"java:comp/env"));
35          }
36          catch (Exception ex) {
37              text.append(ex.toString());            
38          }
39          
40          response.setContentType("text/html");
41          PrintWriter pw = response.getWriter();
42          pw.print("<html>");
43          pw.print("<body>");
44          pw.println("em=" + em);
45          pw.println(text);
46          pw.print("</body>");
47          pw.print("</html>");
48      }
49  }