我试图通过图托利亚点.but运行spring示例,我没有在jsp页面中获取模型地图数据,.I在web/lib文件夹中添加了所有所需的jars,我还在使用<%@ page contentType="text/html; charset=UTF-8" isELIgnored="false" %> .But,但我没有在jsp页面中获取数据。我还在堆栈溢出和http://www.mkyong.com/spring-mvc/modelandviews-model-value-is-not-displayed-in-jsp-via-el/上查看了这个问题的许多答案--这是我的项目flow.Please帮助--提前感谢
。

我的HelloController是
package com.tutorialspoint;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
@Controller
@RequestMapping("/hello")
public class HelloController{
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}web.xml是:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>HelloWeb-servlet.xml是
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>这是我的hello.jsp::
<%@ page contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
hiiiii <h2>${message}</h2>
</body>
</html>发布于 2015-03-22 11:41:37
我解决了这个问题。在结构上有一些问题,我made.Thanks @akfaz..we必须在web中创建一个jsp文件夹,然后必须编写hello.jsp,因为这个code...here是我当前项目流程的屏幕类型,运行良好,我可以使用spring在jsp中获取模型地图/模型和视图的数据。)

发布于 2015-03-15 12:09:35
通常,应用程序将查找文件夹webapp (位于src/main/webapp/中),在那里您应该移动整个WEB文件夹和相应的jsp文件(src/main/webapp/WEB-INF/jsp/hello.jsp)。
但是,您使用的教程(tutorialspoint)假设将整个webapp复制到tomcat中的webapp文件夹中,并使用相应的lib(
一旦您完成了创建源文件和配置文件,导出您的应用程序。右键单击您的应用程序并使用Export文件选项,并将您的HelloWeb.war文件保存在Tomcat的webapp文件夹中。
对于未来,我强烈建议使用像maven这样的构建自动化工具,这将简化流程带有maven的spring。
发布于 2015-03-15 20:07:00
将web.xml xsd模式从2.4更改为3,类似于:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true" version="3.0">https://stackoverflow.com/questions/29060216
复制相似问题