Results 1 to 3 of 3

Thread: jstl model access

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •