我正在开发一个 sturts2 web 应用程序,我有一个带有用户名和密码字段的登录页面。一旦用户提交带有值的表单,我正在验证登录,如果用户提供有效的用户名和密码,它将被重定向到主页。在重定向主页时,我必须调用一个线程,在该线程中我在会话中设置一些数据以供将来使用。这该怎么做 ?
我所做的是
import com.opensymphony.xwork2.ActionContext;
if( loginSuccess(userInfo) ) {
initializeDatas(); // calling thread after userInfo bean validated
// redirecting to home page
return HOME_PAGE;
}
我添加了一个实现可运行的新类。
class intilalizer implements Runnable {
@Override
public void run() {
try {
System.out.println("Started to set values ");
List<String> iphoneSdks = new ArrayList<String>();
List<String> iphoneOSSdks = IosSdkUtil.getMacSdks(MacSdkType.iphoneos);
List<String> simSdks = IosSdkUtil.getMacSdks(MacSdkType.iphonesimulator);
List<String> macSdks = IosSdkUtil.getMacSdks(MacSdkType.macosx);
iphoneSdks.addAll(iphoneOSSdks);
iphoneSdks.addAll(simSdks);
iphoneSdks.addAll(macSdks);
ActionContext context = ActionContext.getContext();
System.out.println("context ===> " + context); // here i am getting null value
String httpRequest = ServletActionContext.HTTP_REQUEST;
System.out.println("httpRequest =====> " + httpRequest);
Object object = context.get(httpRequest);
System.out.println(object);
HttpServletRequest req = (HttpServletRequest) object;
req.setAttribute(REQ_IPHONE_SDKS, iphoneSdks);
req.setAttribute(REQ_IPHONE_SIMULATOR_SDKS, simSdks);
System.out.println("Value initialized@@@@");
} catch (Exception e) {
e.printStackTrace();
}
}
}
我正进入(状态
java.lang.NullPointerException
at com.photon.phresco.framework.actions.intilalizer.run(Login.java:286)
at java.lang.Thread.run(Thread.java:680)
我在线收到此错误。
ActionContext context = ActionContext.getContext();
System.out.println("context ===> " + context); // here i am getting null value