Announcement Announcement Module
Collapse
No announcement yet.
jstl model access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • jstl model access

    How do i access my model object from JSTL? Or preferably w/o using JSTL. I was able to access it when the object was a collection:
    Code:
    <c:forEach items="${myColl}" var="item">
    <jsp:useBean id="item"  type="com.test.Item" />
    <% sb.append("<item>").append(item).appnd("</item>"); %>
    In case you are wondering, my view is serializing the object into XML in this jsp

    When i tried to place a non collection object into ModelAndView, I was not able to access it from jsp:
    Code:
    public ModelAndView login(HttpServletRequest request, 
        						   HttpServletResponse response,
        						   UserLoginCommand cmd
        						   ) throws Exception{
    ...
        user = dao.retrieve(userId);
        return new ModelAndView("user2", "user", user);
    i tried <c:set var="user" value="${user}" />, tried to pry it from session.getAttribute("user"), and from request.getParameter("user'), but none gave me anything.

    Please help

  • #2
    And have you tried request.getAttribute or simply ${user}?

    All the elements in your Model are put into the request attributes with the name given to them.

    Comment


    • #3
      mdeinum, you are correct. I boogered my jsp declarations, and ommited:
      Code:
      <%@ page session="false"%>
      <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
      <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
      once i added them back up, i can now reference my beans and actually forgo jstl all together. mdeinum's tip to use request.getAttribute("user") works and is all I need.

      Comment

      Working...
      X