50,523
社区成员
发帖
与我相关
我的任务
分享
public class LoginAction
{
private String userId;
private String password;
private UserLoginService userLoginService;
public P0101002Action(){
ServletContext context = ServletActionContext.getServletContext(); //上面这句之后context为null,但是如果把这句直接放到execute事件中就可以取到,为何?
}
//........
public String execute(){
ServletContext context = ServletActionContext.getServletContext();
//放到这里则可以取得上下文ServletContext
}
}
Action instance;
synchronized (actions) {
// Return any existing Action instance of this class
try {
instance = (Action) RequestUtils.applicationInstance(className);
// Maybe we should propagate this exception
// instead of returning null.
} catch (Exception e) {
......
}
actions.put(className, instance);
if (instance.getServlet() == null) {
instance.setServlet(this.servlet);
}
}
public class LoginAction
{
private String userId;
private String password;
private UserLoginService userLoginService;
public P0101002Action(){
ServletContext context = ServletActionContext.getServletContext();
//上面这句之后context为null,但是如果把这句直接放到execute事件中就可以取到,为何?
}
//........
public String execute(){
//放到这里则可以取得上下文ServletContext
ServletContext context = ServletActionContext.getServletContext();
}
//...........
}
public LoginAction(){
ServletContext context = ServletActionContext.getServletContext(); //上面这句之后context为null,但是如果把这句直接放到execute事件中就可以取到,为何?
}