Announcement Announcement Module
Collapse
No announcement yet.
Why JSTL expression doesn't work? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why JSTL expression doesn't work?

    Hi, I have a simple application, which show a variable's value in view, and the variable is set in controller, here is my code

    Controller:
    Code:
    package com.sohu.sce.test.web;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.stereotype.Controller;
    
    @Controller
    public class HelloWorld {
    	@RequestMapping(value="/")
    	public String home(Model model)
    	{
    		model.addAttribute("name", "zhixingao");
    		System.out.println(model);
    		return "/WEB-INF/index.jsp";
    	}
    }
    JSP:
    Code:
    <%@ taglib prefix="c" 
               uri="http://java.sun.com/jsp/jstl/core" %>
    <html>
    <body>
    <h2>Hello <c:out value="${name}" />!</h2>
    </body>
    </html>
    POM
    Code:
    <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.sohu.sce</groupId>
      <artifactId>test</artifactId>
      <packaging>war</packaging>
      <version>0.0.1-SNAPSHOT</version>
      <name>test Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
        	<groupId>org.springframework</groupId>
        	<artifactId>spring-webmvc</artifactId>
        	<version>3.2.2.RELEASE</version>
        </dependency>
        <dependency>
        	<groupId>javax.servlet</groupId>
        	<artifactId>jstl</artifactId>
        	<version>1.2</version>
        </dependency>
        <dependency>
        	<groupId>javax.servlet.jsp</groupId>
        	<artifactId>javax.servlet.jsp-api</artifactId>
        	<version>2.3.1</version>
        	<scope>provided</scope>
        </dependency>
      </dependencies>
      <build>
        <finalName>test</finalName>
      </build>
    </project>
    So can anyone tell me what's wrong?

  • #2
    Hello

    Can you show your web.xml? And the real problem (stack trace, 404, no content, ...)

    regards
    Grzegorz Grzybek

    Comment

    Working...
    X