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.
我正在浏览这一页的教程,我有几乎相同的代码。在删除了Apache Commons库和JSTL之类的东西之后,我开始工作了。所有的工作都是有效的,实际上是使用我指定为视图的jsp,但是在呈现站点时,控制器中的变量“message”并没有显示出来。也不是因为表达式语言的问题,因为我也没有得到${message}文本显示。只是一张白纸。
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.
我知道jsp实际上正在被触发的唯一原因是,我在那里放了一个没有其他位置的标题,它正在页面显示中使用。我还知道变量在控制器中被设置,操作被调用是因为我在映射函数中放入了一个简单的sysout。
Thanks for any help!
感谢任何帮助!
EDIT
编辑
Here's the jsp:
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);
}
}
2 个解决方案
#1
4
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"?
你确定问题在显示吗?页面是否加载良好,我的意思是除了“消息”之外,页面上是否显示所有其他HTML ?
EDIT Try to use org.springframework.web.servlet.ModelAndView instead of org.springframework.web.portlet.ModelAndView
尝试使用org.springframe .web.servlet进行编辑。ModelAndView代替org.springframework.web.portlet.ModelAndView
#2
1
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.
您的tomcat可能使用了错误的jstl.jar。在tomcat lib文件夹下,检查jstl是否正确。jar与您的项目使用的版本相同。
#1
4
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"?
你确定问题在显示吗?页面是否加载良好,我的意思是除了“消息”之外,页面上是否显示所有其他HTML ?
EDIT Try to use org.springframework.web.servlet.ModelAndView instead of org.springframework.web.portlet.ModelAndView
尝试使用org.springframe .web.servlet进行编辑。ModelAndView代替org.springframework.web.portlet.ModelAndView
#2
1
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.
您的tomcat可能使用了错误的jstl.jar。在tomcat lib文件夹下,检查jstl是否正确。jar与您的项目使用的版本相同。