Announcement Announcement Module
Collapse
No announcement yet.
Could not display the model in view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not display the model in view

    Hello all,

    I am trying Spring for the first time. Everything seems to work fine expect that I could not display the Model in the view. Here are the codes

    Code:
    private DepartmentBO departmentBO;
    	
    	public void setDepartmentBO(DepartmentBO departmentBO) {
    		this.departmentBO = departmentBO;
    	}
    	
    	public ModelAndView handleRequestInternal(
    			HttpServletRequest request,
    			HttpServletResponse response)
    			throws ServletException, IOException {
    			String deptId = (String) request.getParameter("DeptID");
    			HashMap map = new HashMap();
    			map.put("test", "test");
    			map.put("departments", departmentBO.getDepartments());
    			ModelAndView mav = new ModelAndView("departments", map);
    			return mav;
    		}
    and in *-servlet.xml

    Code:
           <bean name="demoController" class="demo.spring.controller.DemoController">
    		<property name="departmentBO">
    			<ref bean="departmentBO"/>
    		</property>
    	</bean>
    	
    	<bean name="departmentBO" class="demo.spring.bo.DepartmentBO">
        	<property name="sessionFactory">
        		<ref bean="demoSessionFactory"/>
        	</property>	
    	</bean>
    
            <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/index.htm">demoController</prop>
                </props>
            </property>
        </bean>
    in the web.xml

    Code:
    <servlet>
    		<servlet-name>demo</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>2</load-on-startup>
       </servlet>
    
      <servlet-mapping>
        <servlet-name>demo</servlet-name>
        <url-pattern>/test/*</url-pattern>
      </servlet-mapping>
    in the view department.jsp:

    Code:
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <html>
    <body>
    <c:out value="${test}"/>
    <table>
    <c:forEach items="${departments}" var="department" >
    <tr>
    <td>
    <c:out value="${department}"/>
    <a href='employees.jsp?deptId=<c:out value="${department.id}"/>'>"${department.name}"</a>
    </td>
    </tr>
    </c:forEach>
    </table>
    this is the output I get:

    ${test}
    ${department} "${department.name}"

    I am not sure what I am missing. Any help is greatly appreciated.

    thanks
    Aravind

  • #2
    Make sure you have JSP tag libraries in WEB-INF/lib or server's classpath. They are jstl.jar and standard.jar

    Comment


    • #3
      Hi all,

      I'm having the same problem, even if I have jstl.jar and standard.jar files in my /WEB-INF/lib folder.

      Is there anything else I missed?
      I am able to run the Spring countries sample, though.


      nandipinto.

      Comment


      • #4
        I had the same problem

        did you try to reinstall tomcat?

        I used to have this problem, since I reinstall latest tomcat
        never got this problem again.

        Comment


        • #5
          Hi fanfaron,

          Forgot to tell you that I'm using Tomcat within JBoss 4.0.2.
          The strange thing is that I'm able to deploy and run some Spring samples that also use JSTL tags, really dont know what I have miss-configured.

          Haven't tried to use Tomcat alone, though.

          Comment


          • #6
            Looks like EL isn't enabled. Does the top of your web.xml look like this:

            <!DOCTYPE web-app
            PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
            "http://java.sun.com/dtd/web-app_2_3.dtd">

            <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">


            Note the "version" attribute.

            Comment

            Working...
            X