0

My controller contains following code

@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello(Model model) {
model.addAttribute("msg", "Hello world buddy");
return "helloworld";
}

my jsp page as

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://www.springframework.org/tags/form"
prefix="springForm"%>
<!DOCTYPE html">
<html>
<head>
<title>Spring MVC -HelloWorld</title>
</head>
<body>
<springForm:form name="hello" commandName="command" method="GET"
    action="/hello">
    <c:out value='${msg}' />
</springForm:form>
</body>
</html>

but i am getting output

${msg}

i expect output "Hello world buddy"

3 Answers3

2

It also happens to me, in my case my solution was to correct the pom.xml, just verify that your are using the correct version of jstl. This is the pom.xml that I use:

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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.timbuchalka</groupId>
    <artifactId>spring-mvc-demo-1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>
  1. Clean all maven repository

  2. Reload all the dependencies from maven, if you are using eclipse go to righ click to the project select maven and update project.

  3. The example of the pom.xml that I used maybe doesn't have all the dependecies that your are using, but it can give you an idea if your jstl dependency is correct.

  4. There are other post related to this issue, it depends to many reasons, in my case was just the maven dependency.

Related questions:

JSTL c:out not showing the variable's value

spring-mvc-not-getting-value-inside-jsp-view

Daniel C.
  • 5,418
  • 3
  • 23
  • 26
2

Happened with me long time back, issue was with servlet version If you are using xml type application initializer aka web.xml then check for servlet version, refer the below code snippet ... web-app xmlns="http://java.sun.com/xml/ns/j2ee" ...... version="use higher version probably 3.0+"

Madhu Bose
  • 371
  • 4
  • 16
1

add this on top of jsp page.

<%@ page isELIgnored="false" %>
Sajal Gupta
  • 109
  • 1
  • 6