未显示Spring MVC字符串



我正在尝试使用Java学习Web开发,这是我在JavaWeb中的第一个程序。我在Netbeans中使用了Maven项目,并添加了Spring Framework。这只是一个简单的hello世界,但controller.java中的消息在运行时不会显示在index.htm中。我遵循了网上的教程,但我的不起作用。可能是什么问题??

这是我的控制器里的东西

@Controller
public class sampClass {
@RequestMapping("/index")
    public ModelAndView printWelcome(){
        String message = "Hello World";
        return new ModelAndView("index", "message", message);
}
}

我的观点只是

Message: ${message}

那么输出只是

消息:

问题出现在applicationContext.xml中注释未声明为

<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.sample"/>

您可能需要在JSP文件的顶部添加以下内容:

<%@ page isELIgnored="false"%>

以便启用ELI表达式作为${message}

最新更新