This discussion is archived
0 Replies Latest reply: Jan 2, 2009 9:26 AM by 556517 RSS

Session Bean problem

556517 Newbie
Currently Being Moderated
Hi,
i'm creating a webapp which uses the struts 1.2. What it does so far is to allow the user to enter his or her information like name, age ect which is then submitted and stored in a dynamic bean called EmailFormBean.java. Then it is meant to say "Thank you....." with their name at the end. The problem i'm having is retrieving their name and displaying it in the new jsp page called EmailSuccess.jsp. Here is the code listings.

Email_Problem.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
 <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Email Fault</h2>
        <html:form action="ValidateEmailProblem">
            <table border="1" cellpadding="10%" align="center">
                            
                <tr>
                    <td> Please enter your details:
                </tr>
                <tr>
                    <td> Please enter your name: <html:text property="name" size="30" />
                    <td> <html:errors property="name" />
                 
                    <td> <html:submit value="Submit" />
                    <a href="javascript:history.go(-1)" onMouseOver="self.status=document.referrer;return true">Cancel</a> 
                 </tr>
            </table>
        </html:form>
    </body>
</html>
Model bean code: EmailMember.java
package Model;

 
public class EmailMember 
{
    private String emailFaultDesc;
    private String name;
    private int age;
    private int telNo;
    
    public EmailMember(){
        }
  
     public String getName()
    {
        return name;   
    }
      public void setName(String n)
    {
        name = n;
    }
  
Action form: ValidateEmail.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Model.EmailMember;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.validator.DynaValidatorForm;
import org.apache.commons.beanutils.BeanUtils;

public class ValidateEmailProblem extends org.apache.struts.action.Action {   
    private final static String SUCCESS = "success";
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
           EmailMember eMailMem = new EmailMember(); 
           BeanUtils.copyProperties(eMailMem, form);  
           request.getSession().setAttribute("emailPerson", eMailMem);
        return mapping.findForward(SUCCESS);
    }
}
struts-config.xml
<struts-config>
    <form-beans>
        <form-bean name="PasswordForm" type="PasswordForm"/>
        <!-- Use Dynamic Form Bean instead of definning form bean class explicitely -->
          <form-bean name="EmailFormBean" type="org.apache.struts.validator.DynaValidatorForm">
           <form-property name="name" type="java.lang.String"/>
          </form-bean>
    </form-beans>
    <action-mappings>
         </struts-config>
EmailSuccess.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<jsp:useBean id="emailperson"  class="Model.EmailMember"/>
  <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Thank you , ${EmailMember.name}</h2>
        
    </body>
</html>
I also attempted to degug my app in the bean code, for example the name, and it does show that when i do submit the form i see the name in the variable in setName function after i step over the variable.

Any suggestions?

Many thanks