-
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
Code:
try{
StringBean bean = new StringBean();
bean.setBean(value);
request.setAttribute("result", bean);
}catch(Exception e){
e.printStackTrace();
}
Here is my bean class (StringBean)
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
-
Have you tried debugging the code by using println()s?
-
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.
-
Quote:
Yes, it works fine.
??? Then there is no problem if it works. Is that right?
-
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?"
-
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.