ERROR
10:49:40,890 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 39s:250ms 10:49:48,062 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception javax.servlet.jsp.JspException: Missing message for key "Login.userAccountNumber" at org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:235) at org.apache.jsp.Login_jsp._jspx_meth_bean_005fmessage_005f0(Login_jsp.java:253) at org.apache.jsp.Login_jsp._jspx_meth_html_005fform_005f0(Login_jsp.java:209) at org.apache.jsp.Login_jsp._jspService(Login_jsp.java:124) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) at java.lang.Thread.run(Unknown Source)
STEPS I FOLLOWED
I have created a small bank transaction application using EJB and Struts
A)BankEJB
1)Account.java - > Getters and setters
2)Bank.java->Interface(2 Methods) -> i) transfermoney ii) validateaccount
3)BankBean.java - > is the bean wer actual bussiness logic for above 2 methods resides
4)BankHome.java -> create Ejb
5)DatabaseUtil.java - > database connection logic resides here.
6)ejb-jar.xml - >
<ejb-jar> <description>My First EJB</description> <enterprise-beans> <session> <ejb-name>BankEJB</ejb-name> <home>com.myejb.BankHome</home> <remote>com.myejb.Bank</remote> <ejb-class>com.myejb.BankBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> </session> </enterprise-beans> </ejb-jar>
7)jboss.xml - >
<jboss> <enterprise-beans> <session> <ejb-name>BankEJB</ejb-name> <jndi-name>BankObject</jndi-name> </session> </enterprise-beans> </jboss>
then created a jar for this ejb application and then includede in struts library
B)BankSTRUTS
1)LoginAction -> bussiness logic for action taken on click of login
2)TransferAction -> bussiness logic for action taken on click of transfer
3)Home.jsp ->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="java.util.*,com.myejb.*,javax.naming.*"%> <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html:html locale="true"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h1>Bank Welcome Page</h1> <% Account account=null; HttpSession hs=request.getSession(); if(hs!=null) { account =(Account)hs.getAttribute("account"); if(account==null) { hs.setAttribute("login", "Session Expiered... Login Again!"); RequestDispatcher rd=request.getRequestDispatcher("Login.jsp"); rd.forward(request,response); } try{ Context ctx = new InitialContext(); BankHome home=(BankHome)ctx.lookup("BankObject"); Bank bean = (Bank)home.create(); account=bean.validateAccount(account.getAccountNumber(),account.getPassword()); if(account==null){ hs.setAttribute("login","Invalid Loin"); request.getRequestDispatcher("/Login.jsp").forward(request,response); } hs.setAttribute("account", account); }catch(Exception e){ } }else { request.getRequestDispatcher("/Login.jsp").forward(request,response); } %> <table border="1"> <tr> <td> <% if(account!=null) { out.print("<font color='GREEN' face='verdana' size='3'> Wellcome : "+account.getOwnerName()+"</font> "); %> </td> <td> <% out.print("<font color='GREEN' face='verdana' size='3'> Current Balance : "+account.getBalance()+"</font> "); } %> </td> <td> <a href="Logout.jsp">Logout</a></td> </tr> </table> <br></br> <br></br> <html:form action="/GoTransferMoneyAction" method="post" onsubmit="return validateTransferMoneyDinaForm(this);" > <P> <bean:message key="TransferMoney.ToAccount" /><html:text property="toAccount"/><BR> <bean:message key="TransferMoney.Amount" /><html:text property="amount"/><BR> <html:submit ><bean:message key="TransferMoney.Transfer"/></html:submit> </P> </html:form> <% if(hs!=null) { String TransectionStatus =(String)hs.getAttribute("TransectionStatus"); if(TransectionStatus!=null) { out.print("<font color='RED' face='verdana' size='4'>"+TransectionStatus+"</font> "); } } %> <html:javascript formName="TransferMoneyDinaForm"/> </body> </html:html>
4)Login.jsp ->
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.util.*"%> <%@page import="com.myejb.*"%> <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <% response.setHeader("pragma", "no-cache"); response.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); %> <html:html locale="true"> <body> <br> <html:errors /> <br> <html:form action="/GoLoginAction" method="post" onsubmit="return validateLoginDinaForm(this);"> <P> <bean:message key="Login.userAccountNumber"/> <html:text property="userAccountNumber"/><BR> <bean:message key="Login.userPassword"/> <html:password property="userPassword"/><BR> <html:submit ><bean:message key="login.Login"/></html:submit> </P> </html:form> <% HttpSession hs=request.getSession(); if(hs!=null) { String loginStatus =(String)hs.getAttribute("login"); if(loginStatus!=null) { out.print("<font color='RED' face='verdana' size='4'>"+loginStatus+"</font> "); hs.invalidate(); } } %> <html:javascript formName="LoginDinaForm"/> </body> </html:html>
5)Menu.jsp -> 2 option i) Do Transfer ii) Balance Enq
6)Logout.jsp ->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.util.*,com.myejb.*,javax.naming.*"%> <!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>Insert title here</title> </head> <body> <% HttpSession hs=request.getSession(); if(hs!=null) { Account account =(Account)hs.getAttribute("account"); if(account!=null) hs.setAttribute("account",null); hs.invalidate(); } request.getRequestDispatcher("/Login.jsp").forward(request,response); %> </body> </html>
7)validations.xml - >
<formset> <!-- An example form --> <form name="LoginDinaForm"> <field property="userAccountNumber" depends="required"> <arg key="login.UserACNumber" /> </field> <field property="userPassword" depends="required,mask"> <arg key="login.Passeword"/> <var> <var-name>mask</var-name> <var-value>^[0-9a-zA-Z]*$</var-value> </var> </field> </form> <form name="TransferMoneyDinaForm"> <field property="toAccount" depends="required"> <arg key="TransferMoney.ToAccount" /> </field> <field property="amount" depends="required"> <arg key="TransferMoney.Amount" /> </field> </form> </formset>
8)struts-config.xml ->
<form-bean name="LoginDinaForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="userAccountNumber" type="java.lang.String"> </form-property> <form-property name="userPassword" type="java.lang.String"> </form-property> </form-bean> <form-bean name="TransferMoneyDinaForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="toAccount" type="java.lang.String"> </form-property> <form-property name="amount" type="java.lang.Double"> </form-property> </form-bean>
9) MessageResources.properties - >
login.UserACNumber=User Account Number login.Passeword=User Password login.Login=Login TransferMoney.ToAccount= To Account TransferMoney.Amount= Amount TransferMoney.Transfer= Transfer