Omn*_*ent 5 java serialization glassfish
我们刚刚切换到Glassfish V2.我们现在在设置会话属性时遇到错误.
错误是:
java.lang.IllegalArgumentException: PWC2788: setAttribute: Non-serializable attribute
Run Code Online (Sandbox Code Playgroud)
代码是:
getRequest().getSession().setAttribute("questionsForUser", getQuestions());
Run Code Online (Sandbox Code Playgroud)
getQuestions()只是一个简单的getter,它位于名为'Parent Action'的抽象类中....所以为了使getQuestions()成为一个序列化对象,我的类需要实现可序列化吗?:
public List getQuestions() {
return questions;
}
Run Code Online (Sandbox Code Playgroud)
编辑:我正在使用ORM(iBatis)
关于"问题"的更多信息
二传手:
public void setQuestions(List questions) {
this.questions = questions;
}
Run Code Online (Sandbox Code Playgroud)
在此方法中调用setter.此方法调用iBatis映射.
public void prepareQuestions()
{
setExamIfaceDAO((SecurityExamIfaceDAO)ApplicationInitializer.getApplicationContext().getBean("securityExamIfaceDAO"));
String userRole = questionsBasedOnUserRole();
int questionsToBeShown = 0;
if (userRole.equalsIgnoreCase("C"))
questionsToBeShown = 15;
else if (userRole.equalsIgnoreCase("U"))
questionsToBeShown = 10;
List local_questions = getExamIfaceDAO().getSecurityQuestions(userRole);
Collections.shuffle(local_questions);
if (local_questions.size()>=questionsToBeShown)
setQuestions(local_questions.subList(0, questionsToBeShown));
getRequest().getSession().setAttribute("questionsForUser", getQuestions());
}
Run Code Online (Sandbox Code Playgroud)
And*_*ndy 10
您可以使用可序列化的List实现使对象可序列化,并确保列表中的对象也可序列化.
是 - 最好只在会话中放置可序列化的对象,因为这样可以让您的应用程序在具有多个节点的服务器上运行.即使您现在不关心这一点,它在将来可能会有用.
servlet容器应确保不在用户之间交换会话.使存储在会话中的对象可序列化允许容器在群集中的多个节点之间"分配"会话状态,从而允许拥有会话的用户具有由任何节点服务的请求.
| 归档时间: |
|
| 查看次数: |
22225 次 |
| 最近记录: |