-none- 2007-08-15 - By red phoenix
Back For general Java class,we can make construction function,like this: public class test{ String a; public test(String a){ this.a=a; } }
I don't know if I can do it like above code under struts2 action,for some reason,I want to initialize some variable and assign some value to it,like follows: public class MyClass extends ActionSupport{ private ....; public MyClass(SomeType s){ //make some common operaction,such get session and so on,because I want to run them only once } public String execute() throws Exception { .... } public String .....{ } ... }
I can successly compile above code,but when I run above code,it will say error: 1)MyClass action error 2)java.lang.NullException because some code in MyClass(SomeType s)
When I remove the code in the MyClass(SomeType s) into execute() function,it can run well. I am puzzle with it! Anybody could tell me how to do it? An example is better.
Thanks, phoenix
|
|