Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Struts Application, Complies perfectly but error at run time

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Exclamation Struts Application, Complies perfectly but error at run time

    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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Current Balance : "+account.getBalance()+"</font> ");
    }
    %>
    </td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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
    Last edited by Json; May 12th, 2010 at 06:23 AM. Reason: Please use code tags.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Struts Application, Complies perfectly but error at run time

    Hello there,

    You need to have a look in your MessageResources.properties file again.

    Make sure that the property Login.userAccountNumber actually exists. Looking at your post above it appears it does not, you have login.UserACNumber instead.

    // Json

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Struts Application, Complies perfectly but error at run time

    Hey hi
    I did check it out and made changes accordingly but still its not working.

    MEssageResources.properties

    login.userAccountNumber=User Account Number
    login.userPassword=User Password
    login.Log=Login

    And accordingly made changes in Login.jsp

    <html:form action="/GoLoginAction" method="post" onsubmit="return validateLoginDynaForm(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.Log"/></html:submit>
    </P>
    </html:form>

Similar Threads

  1. JDBCrealm FORM based problem. But BASIC working perfectly alright!
    By salman4u in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: January 27th, 2010, 09:06 PM
  2. Struts drop down
    By kalees in forum Web Frameworks
    Replies: 1
    Last Post: January 15th, 2010, 12:56 AM
  3. Replies: 0
    Last Post: December 3rd, 2009, 04:43 PM
  4. Struts 1.3.8 and tiles
    By jsnx7 in forum Web Frameworks
    Replies: 3
    Last Post: July 21st, 2009, 03:29 AM
  5. Website to study Struts framework
    By kirman in forum Java IDEs
    Replies: 2
    Last Post: October 17th, 2008, 07:26 AM