开发者

Spring variables not carrying into view

开发者 https://www.devze.com 2023-02-23 00:31 出处:网络
I\'m very new to Spring and can\'t seem to figure out what\'s wrong here. I\'m sure it has to be something simple, but anyway:

I'm very new to Spring and can't seem to figure out what's wrong here. I'm sure it has to be something simple, but anyway:

I was going through the tutorial on this page, and I have nearly identical code. After pulling down the Apache Commons library and the JSTL stuff, I was in business. Everything works, down to it actually using the jsp I specified as the view, but the variable "message" in the controller is not being displayed when the site is rendered. It's not because of the expression language stuff, either, because I'm not getting the ${message} text displaying either. It's just a blank page.

The only reason I know that the jsp is actually being triggered is because I put a title in there that is no where else and it is being used on page display. I also know that the variable is being set in the controller and the action is being called because of a simple sysout that I put in the mapped function.

Thanks for any help!

EDIT

Here's the jsp:

<%@page contentType="text/html" pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>om nom JSP Page</title>
    </head>
    <body>
        ${message}
    </body>
</html>

And the controller:

package org.me.home.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework开发者_如何学编程.web.portlet.ModelAndView;

@Controller
public class SomeController {

    @RequestMapping("/somepage")
    public ModelAndView someAction() {

        String mymsg = "Saying hi!";
        System.out.println(mymsg);
        return new ModelAndView("somepage", "message", mymsg);
    }
}


Try to use such a construction:

<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:out value="${message}" />

And are you sure, that the problem is in displaying? Is page loaded fine, I mean is all other HTML displayed on page, besides "message"?

EDIT Try to use org.springframework.web.servlet.ModelAndView instead of org.springframework.web.portlet.ModelAndView


Your tomcat maybe using the wrong jstl.jar. Under your tomcat lib folder, check if your jstl.jar is the same version you are using with your project.

0

精彩评论

暂无评论...
验证码 换一张
取 消