I am trying to implement the MVC2 model. I have a Servlet that fetches data from a session bean and forwards the entity from the servlet to a jsp:
public class MyServlet extends HttpServlet{
@EJB UserFacade userFacade;
//Fetch the user from the session bean
Users currUser=userFacade.find(userName);
...
request.setAttribute("user", currUser);
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
}
在index.jsp中:我从请求中获取用户,如果我使用scriptlets标记,我可以打印它的名称,但当我使用EL时,不会打印任何内容:
<@page import="Entities.Users">
<"Users currUser = (Users)request.getAttribute("user");">
<= currUser.getName() > -OK!
${currUser.name}-Nothing is printed!
How should I include/forward the session-bean into the JSP in order to be able to use EL (and avoid using scriptlets)?
Is this the preferred way to implement the Model View controller?