java - Spring passing ModelMap model attributes to JSP -
i having problems passing modelmap attribute tsp page. intelij idea recognizes variable passing well, when deploy application on tomcat, , actual page loaded, can see variable names, instead of variable values. trying print data .jsp view.
web.xml:
<!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 version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name>orange home web application</display-name> <!-- definition of root spring container shared servlets , filters --> <context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/mvc-dispatcher-servlet.xml /web-inf/spring/root-context.xml /web-inf/spring/application-security.xml </param-value> </context-param> <filter-mapping> <filter-name>springsecurityfilterchain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>springsecurityfilterchain</filter-name> <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class> </filter> <!-- processes application requests --> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- creates spring container shared servlets , filters --> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.log4jconfiglistener</listener-class> </listener> </web-app>
pom.xml:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.boro</groupid> <artifactid>orange</artifactid> <packaging>war</packaging> <version>1.0-snapshot</version> <name>orange maven webapp</name> <url>http://maven.apache.org</url> <!-- properties definitions --> <properties> <org.springframework.version>4.0.9.release</org.springframework.version> <org.springframework.security.version>3.2.3.release</org.springframework.security.version> <org.apache.tiles.version>3.0.3</org.apache.tiles.version> </properties> <!-- project dependencies --> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- spring --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-tx</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${org.springframework.version}</version> </dependency> <!-- spring security --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> <version>${org.springframework.security.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-taglibs</artifactid> <version>${org.springframework.security.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-config</artifactid> <version>${org.springframework.security.version}</version> </dependency> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-crypto</artifactid> <version>${org.springframework.security.version}</version> </dependency> <!-- hibernate --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>4.3.5.final</version> </dependency> <!-- java servlet , jsp dependencies --> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> </dependency> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>jsp-api</artifactid> <version>2.1</version> <scope>provided</scope> </dependency> <!-- jstl dependency --> <dependency> <groupid>jstl</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <!-- apache commons dbcp dependency --> <dependency> <groupid>org.apache.commons</groupid> <artifactid>commons-dbcp2</artifactid> <version>2.0</version> </dependency> <!-- mysql connector java dependency --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.30</version> </dependency> <!-- logger --> <dependency> <groupid>org.apache.logging.log4j</groupid> <artifactid>log4j-api</artifactid> <version>2.2</version> </dependency> <dependency> <groupid>org.apache.logging.log4j</groupid> <artifactid>log4j-core</artifactid> <version>2.2</version> </dependency> <!-- apache tiles dependencies --> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-api</artifactid> <version>${org.apache.tiles.version}</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-core</artifactid> <version>${org.apache.tiles.version}</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-jsp</artifactid> <version>${org.apache.tiles.version}</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-servlet</artifactid> <version>${org.apache.tiles.version}</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-template</artifactid> <version>${org.apache.tiles.version}</version> </dependency> <!-- logger tool --> <dependency> <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>1.2.16</version> </dependency> <dependency> <groupid>net.sourceforge.htmlunit</groupid> <artifactid>htmlunit</artifactid> <version>2.15</version> </dependency> <dependency> <groupid>xml-apis</groupid> <artifactid>xml-apis</artifactid> <version>1.4.01</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>1.5.8</version> </dependency> </dependencies> <build> <finalname>orange</finalname> </build>
here controller:
@requestmapping(value = "/", method = requestmethod.get) public string home(modelmap model) { model.addattribute("hello", "hello"); log.info("loading home.jsp"); return "home"; }
and here home.jsp page:
<%@ page contenttype="text/html;charset=utf-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <c:set var="contextpath" value="${pagecontext.request.contextpath}"/> <div class="content-wrapper"> <!-- main content --> <section class="content"> <h1> parameter: ${hello} parameter: <c:out value="${hello}"/> </h1> </section> </div>
when home page loaded can see variable names instead of values: parameter: ${hello} parameter: ${hello}
<!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 version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
when @ header notice <!docype
line points old version of web app 2.3 disables el. fix remove line.
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
that should solve problem.
Comments
Post a Comment