アクション クラスからセッションに属性を設定しようとしています
public String execute() {
String result = Action.SUCCESS;
if (username.equals("pavan") && password.equals("kumar")){
System.out.println("Success");
Map<String, Object> session = new HashMap<String, Object>();
session.put("username", username);
session.put("role", 1);
ActionContext.getContext().setSession(session);
return Action.SUCCESS;
}
else{
System.out.println("Input");
return Action.INPUT;
}
}
ユーザー名とパスワードが有効で、適切な JSP に移動すると、成功が返されます。しかし、設定したセッション属性はjspに表示されません
<% if(session == null || session.getAttribute("username") == null) {
System.out.println("No valid session found");
response.sendRedirect("/Test/index.jsp");
}%>
上記のコードは、jsp がリダイレクトさindex.jsp
れ"No valid session found"
、コンソールに出力されます。
私は何が欠けていますか?