Versions Compared

Key

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

...

Creating application client

  1. Create a new dynamic Web Project with the name Application Client.
  2. Right click on WEB-INF and create the following jsp
    Code Block
    titlelogin.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>Welcome to Apache Geronimo</title>
    </head>
    <body bgcolor="white">
    <form method="post" action="passCredentials.jsp">
    <h2 align="center"><font color="blue">Welcome to Apache Geronimo</font></h2>
    <h2 align="center"><font color="blue">Enter your credentials</font></h2>
    Enter your Username
    <input type="text" name="username" size=20><br>
    Enter your Password
    <input type="password" name="password" size=20><br>
    <input type="submit" value="Login">
    <a href="http://localhost:8080/ApplicationClient/register.jsp">NewUser</a>
    </form>
    </body>
    </html>
    
    Code Block
    titlepassCredentials.jsp
    borderStylesolid
    
    <%@ page import="java.util.Properties,javax.naming.Context,javax.naming.InitialContext,statelessejb.RegisterBeanRemote" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body bgcolor="yellow">
    <%!boolean i; %>
    <%
    System.out.println("Enter");
    Properties prop=new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
    	prop.put("java.naming.provider.url", "ejbd://localhost:4201");
    Context context = new InitialContext(prop);
    System.out.println(context);
    RegisterBeanRemote myejb=(RegisterBeanRemote)context.lookup("RegisterBeanRemote");
    String s= request.getParameter("username");
    String s1= request.getParameter("password");
    System.out.println("EJB");
    i=myejb.verify(s,s1);
    System.out.println(i);
    %>
    <% 
    	if (i==true){ 
    %>
    <jsp:forward page="/resources.jsp"></jsp:forward>
    <% 
    	} else {
    %>
    	<jsp:forward page="/login.jsp"></jsp:forward>
    <% 
    }
    %>
    </body>
    </html>
    
    Code Block
    titleresources.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>Welcome to Apache Geronimo</title>
    </head>
    <body bgcolor="white">
    <h3><font color="blue">Welcome to Apache Geronimo Resource Center</font></h3> 
    Apache Geronimo Home Page
    <a href="http://geronimo.apache.org">Apache Geronimo Home page</a><br>
    Join our mailing list
    <a href="http://geronimo.apache.org/mailing-lists.html">Apache Geronimo Mailing List</a><br>
    Come and Contribute to Apache Geronimo V2.1 Documentation
    <a href="http://cwiki.apache.org/GMOxDOC21/">Apache Geronimo V2.1 Documentation</a>
    </body>
    </html>
    
    Code Block
    titleregister.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>Welcome to Apache Geronimo</title>
    </head>
    <body bgcolor="white">
    <script type="text/javascript">
    function valForm()
    {
    	if (this.document.form1.username.value=="" || this.document.form1.username.value=="")
    	{
    		alert("You cannot leave the field blank");
    		this.document.form1.firstname.focus();
    		return false;
    	}
    	else
    	{
    		return true;
    	}
    }
    </script>
    <h2 align="center"><font color="blue">Welcome to Apache Geronimo User Registration</font></h2>
    <form method="post" name="form1" action="passVariables.jsp" onSubmit=" return valForm();">
    FirstName
    <INPUT type="text" name="firstname" SIZE=20><br>
    LastName
    <INPUT type="text" name="lastname" SIZE=20 ><br>
    Sex<br>
    <input type="radio" name="sex" value="male"> Male
    <br>
    <input type="radio" name="sex" value="female"> Female
    <br>
    Select a UserName<br>
    <input type="text" name="username" size=20><br>
    Select a Password<br>
    <input type="password" name="password"  size=20><br>
    <br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>
    
    Code Block
    titlepassVariables.jsp
    borderStylesolid
    
    <%@ page import="java.util.Properties,javax.naming.Context,javax.naming.InitialContext,statelessejb.RegisterBeanRemote" %>
    
    <html>
    <head>
    
    <meta http-equiv="Refresh" content="5;URL=http://localhost:8080/ApplicationClient/login.jsp">
    <title>Insert title here</title>
    </head>
    
    <%
    Properties prop=new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
    	prop.put("java.naming.provider.url", "ejbd://localhost:4201");
    Context context = new InitialContext(prop);
    RegisterBeanRemote myejb=(RegisterBeanRemote)context.lookup("RegisterBeanRemote");
    String s= request.getParameter("firstname");
    String s1= request.getParameter("lastname");
    String s2= request.getParameter("sex");
    String s3= request.getParameter("username");
    String s4= request.getParameter("password");
    myejb.register(s,s1,s2,s3,s4);
    %>
    
    <h3 align="center"><font color="blue">Thank you for registering with Apache Geronimo</font></h3>
    <h3 align="center"><font color="blue">Redirecting to Login Page</font></h3>
    </html>
    

    Few more configurations

  1. In the EJB Project. Under META-INF, Edit openejb-jar.xml and add the following
    Code Block
    titledatasource dependency
    borderStylesolid
    <sys:dependencies>
                <sys:dependency>
                    <sys:groupId>console.dbpool</sys:groupId>
                    <sys:artifactId>jdbc%2Fuserds</sys:artifactId>
                </sys:dependency>        
    </sys:dependencies>
    
    Info
    titleWhere did the above dependencies come from??

    To make the datasource visible to EJB we need to add a dependency to the EJB deployment plan that is openejb-jar.xml. The above element can be obtained automatically from Geronimo Database Pool wizard. Select usage against the database pool jdbc/userds