Student table
Step 2: Create a new Java Web Application project and give any name such as 'MyEJBApplication' and select the server as 'Glassfish' (Mostly everything would be present by default)
Step 3: Create a JDBC Connection Pool (Right click on Project name -> New -> Other -> Glassfish(folder) -> JDBC Connection Pool)
Step 4: Select MySQL from the dropdown box as shown below. ( Note the name of the connection pool) - in this case it is 'connectionPool')
Step 5: Provide the host, port (within the URL parameter), username and password of your mysql database as shown below:
Step 6: Create a JDBC Resource (Right click on Project name -> New -> Other -> Glassfish(folder) -> JDBC Resource).
Step 7: Select the JDBC connection pool name you just in created above (step 4) from the drop down box. Provide a JNDI name as shown:
Step 8: Create a Persistence Unit (Right click on Project name -> New -> Other -> Persistence -> Persistence Unit).
Step 9: Provide a name to the Persistence Unit and select the data source name which you gave while creating the JDBC Resource above (step 7). (Note that the table generation strategy is set to 'None')
Step 10: Create 3 JSP Pages namely home.jsp, login.jsp and error.jsp and insert the following codes respectively
home.jsp
login.jsp
error.jsp
Step 11: Create 3 packages as follows:
Step 11.1: First package com.model and create 2 Entity beans namely 'Login' and 'Student' and insert the following codes respectively.
com.model.Login.java
com.model.Student.java
Step 11.2: Second package com.dao that contains the Session Beans (create by right click on project name -> New -> Session Bean) namely 'LoginDAO' and 'StudentDAO'. ( Both these session beans implement methods from a local interface. Select the 'Local Interface'option while creating the session beans. The LoginDAOLocal and StudentDAOLocal will be automatically created). Add the following respective codes to the session beans and their interfaces appropriately.
com.dao.LoginDAO
com.dao.LoginDAOLocal
com.dao.StudentDAO
com.dao.StudentDAOLocal
Step 11.3: Third package com.controller that contains the servlets namely 'LoginServlet' and 'StudentServlet' and add the following codes respectively.
com.controller.LoginServlet
com.controller.StudentServlet
Step 12: Check your configuration files(web.xml, persistence.xml and glassfish-resources.xml). They should be as follows:
web.xml
persistence.xml
glassfish-resources.xml
Step 13: The final directory structure of the entire project should look as follows:
Step 14: Run the application by Right click on the project name -> Run
14.a: You should see login.jsp. Provide the username as 'admin' and password as 'admin' (as given in the login table in mydatabase) and click on Login.
14.b: You can now add, edit, delete or search for student records from the student table.