Results 1 to 6 of 6
  1. #1
    impact is offline Member
    Join Date
    May 2008
    Posts
    18
    Rep Power
    0

    Default Bean class error

    Can some one tell me why the value from the servlet class is not reaching the bean class?

    Here is my servlet

    Java Code:
    try{
            StringBean bean = new StringBean();
            bean.setBean(value);
            request.setAttribute("result", bean);
            }catch(Exception e){
                e.printStackTrace();
            }
    Here is my bean class (StringBean)

    Java Code:
    package pack01;
    
    public class StringBean{
        private String answer="Hi";
    
        public void setBean(String value){
            answer = value;
        }
        
        public String getBean(){
            return(answer);
        }
    }
    When I run my program I only see Hi as the output. Some how the value is not reaching the StringBean class.

    Many thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Have you tried debugging the code by using println()s?

  3. #3
    impact is offline Member
    Join Date
    May 2008
    Posts
    18
    Rep Power
    0

    Default

    Yes, it works fine. Some how I am not able to transfer the value to StringBean as I am able to get Hi as the output.

    Thanks for your help.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Yes, it works fine.
    ??? Then there is no problem if it works. Is that right?

  5. #5
    impact is offline Member
    Join Date
    May 2008
    Posts
    18
    Rep Power
    0

    Default

    I think I dint understand your question. What works fine is, when I try to print the value using the servlet it actually prints the value. When use StringBean class, that is from servlet send the value to the StringBean class and then try print the out put, all I get is "Hi", which is the default String variable value in StringBean class.

    some how I am not able to transfer the calculated value from the Servlet to the StringBean class and then print it.

    by the way, what did you mean by "Have you tried debugging the code by using println()s?"

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Put a println() statement in the set method to see is it's called and with what value.
    Also use println() to see if the object you put/set in attributes is the same as the one being used with the get method.
    Last edited by Norm; 08-16-2008 at 04:37 PM.

Similar Threads

  1. Replies: 1
    Last Post: 01-29-2009, 09:35 AM
  2. Error deploying Entity Bean
    By RobertoWIN_MX in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 05-01-2008, 05:17 AM
  3. Replies: 0
    Last Post: 09-26-2007, 08:36 PM
  4. Error in class
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-09-2007, 04:06 PM
  5. Struts tag error with bean:write
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-07-2007, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •