Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ModelMap未将bean传递给jsp_Java_Jsp_Spring Mvc - Fatal编程技术网

Java ModelMap未将bean传递给jsp

Java ModelMap未将bean传递给jsp,java,jsp,spring-mvc,Java,Jsp,Spring Mvc,我的应用程序有问题。我正在使用SpringMVC、Maven和Hibernate。我只是想在jsp视图中打印一些数据。我的web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.s

我的应用程序有问题。我正在使用SpringMVC、Maven和Hibernate。我只是想在jsp视图中打印一些数据。
我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>app</display-name> 
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
我的型号:

public class UserModel
{
    private String name;
    private String age;
    // setters and getters
}
现在,问题是我的jsp没有从bean返回值。我发现了一个类似的问题,但没有解决任何问题

我的jsp“主页”页面的一部分:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome page</title>
</head>
<body>
     ${simpleString} <br/> <!-- this works fine -->
     ${simpleNumber} <br/> <!-- this works fine also -->
     ${um.name} <!-- this return nothing -->
     ${um.age} <!-- same here -->
</body>
</html>

欢迎页面
${simpleString}
${simpleNumber}
${um.name} ${um.age}
因为在控制器中,您可以这样做

model.addAttribute("userModel", um);

字符串是属性的名称,它可以是您想要的任何内容

Try
userModel.name
在jsp中
${um.name} <!-- this return nothing -->
${userModel.name}
model.addAttribute("userModel", um);