I am trying to put attributes to session from my action class
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;
}
}
Success will be returned when username and password are valid and goes to appropriate JSP. but session attributes i did set are not visible in jsp
<% if(session == null || session.getAttribute("username") == null) {
System.out.println("No valid session found");
response.sendRedirect("/Test/index.jsp");
}%>
Above code is the jsp will redirect to index.jsp
and "No valid session found"
will be printed in console.
What am i missing?