Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Right click under Project Explorer and Select New->Dynamic Web Project.





  2. Name the project as StatefulClient and Select Next.





  3. Keep the default settings as shown in the figure. Select Next.





  4. On the next screen keep default values. Select Next.





  5. Default values on this screen too. Select Finish.





  6. Right click on the StatefulClient project and Select New->Servlet.





  7. Name the package as ejb.stateful and Servlet as Controller.





  8. Keep the default values and Select Next.





  9. Keep the default values and Select Finish.





  10. Once the servlet is created it shows error. This is due to servlet api missing from the runtime. This can be easily resolved. Right click on StatefulClient project and Select properties.





  11. On the next screen select Java build path and select Libraries.





  12. Select Add External jars.





  13. Browse to your <GERONIMO_HOME>\repository\org\apache\geronimo\specs\geronimo-servlet_2.5_spec\1.1.2 and select geronimo-servlet_2.5_spec-1.1.2.jar and Select Open.





  14. Select Ok on the next screen this will remove all the errors.





  15. Add the following code to Controller.java servlet.
    Code Block
    titleController.java
    borderStylesolid
    package ejb.stateful;
    
    import java.io.IOException;
    import javax.ejb.EJB;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    //import ejb.stateless.AccountCreator;
    
    /**
     * Servlet implementation class for Servlet: Controller
     *
     */
     public class Controller extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
       static final long serialVersionUID = 1L;
       @EJB
       AccountCreator ac;
        /* (non-Java-doc)
    	 * @see javax.servlet.http.HttpServlet#HttpServlet()
    	 */
    	public Controller() {
    		super();
    	}   	
    	
    	/* (non-Java-doc)
    	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	if ( (request.getRequestURI()).equals("/StatefulClient/Controller"))
    	{
    		PersonalInfo personalinfo=new PersonalInfo();
    		personalinfo.setFirstName(request.getParameter("FirstName"));
    		personalinfo.setLastName(request.getParameter("LastName"));
    		personalinfo.setNationality(request.getParameter("Nationality"));
    		personalinfo.setUserName(request.getParameter("UserName"));
    		personalinfo.setPassword(request.getParameter("Password"));
    		ac.addPersonalInfo(personalinfo);
    		RequestDispatcher rd=request.getRequestDispatcher("BillingInfo.jsp");
    		rd.forward(request, response);
    		
    	}
    	else
    	{
    		BillingInfo billingInfo=new BillingInfo();
    		billingInfo.setBank(request.getParameter("Bank"));
    		billingInfo.setCardno(request.getParameter("CardNo"));
    		billingInfo.setCity(request.getParameter("City"));
    		billingInfo.setCountry(request.getParameter("Country"));
    		billingInfo.setHouseNo(request.getParameter("HouseNo"));
    		billingInfo.setPincode(request.getParameter("PinCode"));
    		billingInfo.setStreet(request.getParameter("Street"));
    		ac.addBillingInfo(billingInfo);
    		ac.createAccount();
    	}
    		
    	}
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		doProcess(request, response);
    	}  	
    	
    	/* (non-Java-doc)
    	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		doProcess(request, response);
    		// TODO Auto-generated method stub
    	}   	  	    
    }
    



  16. This code contains EJB specific annotation and so we need to add EJB spec definition to the project. Follow the previous procedure to Add External jars and browse to <GERONIMO_HOME>\repository\org\apache\geronimo\specs\ geronimo-ejb_3.0_spec\1.0.1 and add geronimo-ejb_3.0_spec-1.0.1.jar to java build path. This servlet also contains code referring to bean interface class and PersonalInfo and BilllingInfo class. We need to add these projects to the build path so that the classes can be compiled. Right click on StatefulClient project and Select Properties->Java Build Path->Projects. Select Add.





  17. Check StatefulBean and Select Ok.





  18. Once done the project will be visible in the build path. Select Ok.





  19. Next step is to add jsp pages to our client project. Right click on WebContent under StatefulClient project and Select New->jsp.


    !web18.jsp!


  20. Name the jsp as PersonalInfo.jsp and Select Next.


    !web19.jsp!


  21. On the next screen select Finish.


    !web20.jsp!


  22. Add the following code to PersonalInfo.jsp.


    Code Block
    titlePersonalInfo.jsp
    borderStylesolid
    
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>User Personal Information</title>
    </head>
    <body>
    <form action="Controller">
    <h1>Enter your personal information</h1>
    <table>
    <tr>
    <td><h3>Name</h3></td>
    </tr>
    <tr>
    <td>FirstName</td>
    <td><input type="text" name="FirstName"></td>
    </tr>
    <tr>
    <td>LastName</td>
    <td><input type="text" name="LastName"></td>
    </tr>
    <tr><td><h3>Nationality</h3></td></tr>
    <tr>
    <td>Nationality</td>
    <td><input type="text" name="Nationality"></td>
    </tr>
    <tr><td><h3>Login</h3></td></tr>
    <tr>
    <td>UserName</td>
    <td><input type="text" name="UserName"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input type="password" name="Password"></td>
    </tr>
    </table>
    <input type="submit" Name="Next">
    </form>
    </body>
    </html>
    



  23. Similarly add another jsp with the name BillingInfo.jsp and add the following code.


    Code Block
    titleBillingInfo.jsp
    borderStylesolid
    
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>User Billing Information</title>
    </head>
    <body>
    <form action="Controller1">
    <h1>Enter your Billing information</h1>
    <table>
    <tr>
    <td><h3>Address</h3></td>
    </tr>
    <tr>
    <td>House No</td>
    <td><input type="text" name="HouseNo"></td>
    </tr>
    <tr>
    <td>Street</td>
    <td><input type="text" name="Street"></td>
    </tr>
    <tr>
    <td>City</td>
    <td><input type="text" name="City"></td>
    </tr>
    <tr>
    <td>PinCode</td>
    <td><input type="text" name="PinCode"></td>
    </tr>
    <tr>
    <td>Country</td>
    <td><input type="text" name="Country"></td>
    </tr>
    <tr><td><h3>Credit Card Information</h3></td></tr>
    <tr>
    <td>Bank</td>
    <td><input type="text" name="Bank"></td>
    </tr>
    <tr>
    <td>Card No</td>
    <td><input type="text" name="CardNo"></td>
    </tr>
    </table>
    <input type="submit" name="Submit">
    </form>
    </body>
    </html>