Spring mvc SpringMVC模型图

Spring mvc SpringMVC模型图,spring-mvc,Spring Mvc,我创建了一个SpringMVC+Maven Web应用程序,我试图使用控制器中的ModelMap将一些值传递给jsp,但当我试图在jsp中打印它们时,我无法看到这些值,而是看到了我为打印这些值而编写的相同标记 for this I am using Java 1.7 Spring 4.2.1 Apache Tomcat 8 web server pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h

我创建了一个SpringMVC+Maven Web应用程序,我试图使用控制器中的ModelMap将一些值传递给jsp,但当我试图在jsp中打印它们时,我无法看到这些值,而是看到了我为打印这些值而编写的相同标记

for this I am using 
Java 1.7
Spring 4.2.1
Apache Tomcat 8 web server
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.users</groupId>
    <artifactId>UserManagement</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>UserManagement Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <jdk.version>1.7</jdk.version>
        <spring.version>4.2.1.RELEASE</spring.version>
        <jstl.version>1.2</jstl.version>
        <servletapi.version>3.1.0</servletapi.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servletapi.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <!-- <plugin> 
                        <groupId>org.apache.maven.plugins</groupId> 
                        <artifactId>maven-eclipse-plugin</artifactId> 
                        <version>2.9</version> <configuration> 
                        <downloadSources>true</downloadSources> 
                        <downloadJavadocs>true</downloadJavadocs> 
                        <wtpversion>2.0</wtpversion> 
                        <wtpContextName>spring3</wtpContextName> 
                </configuration> </plugin> -->
        </plugins>
        <finalName>UserManagement</finalName>
    </build>
</project>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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-4.0.xsd 
    http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <context:component-scan base-package="com.user.controller" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/jsps/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <mvc:annotation-driven />

</beans>
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
hello1.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>`enter code here`
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    ${hMessage}
    <br /> 
    ${wMessage}
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Hello</title>
</head>
<body>
    ${helloMessage}
    <br /> 
    ${welcomeMessage}
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>DaDheeChi</title>
</head>
<body>

    <a href="abc.html">Click here to read hello and welcome
        message </a>

    <br/>
    <form action="abc.do" method="get">
        <input type="submit" value="Click" />
    </form>
</body>
</html>

`在这里输入代码`
${hMessage}

${wMessage}
hello.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>`enter code here`
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    ${hMessage}
    <br /> 
    ${wMessage}
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Hello</title>
</head>
<body>
    ${helloMessage}
    <br /> 
    ${welcomeMessage}
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>DaDheeChi</title>
</head>
<body>

    <a href="abc.html">Click here to read hello and welcome
        message </a>

    <br/>
    <form action="abc.do" method="get">
        <input type="submit" value="Click" />
    </form>
</body>
</html>

你好
${helloMessage}

${welcomeMessage}
springservlet.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.users</groupId>
    <artifactId>UserManagement</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>UserManagement Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <jdk.version>1.7</jdk.version>
        <spring.version>4.2.1.RELEASE</spring.version>
        <jstl.version>1.2</jstl.version>
        <servletapi.version>3.1.0</servletapi.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servletapi.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <!-- <plugin> 
                        <groupId>org.apache.maven.plugins</groupId> 
                        <artifactId>maven-eclipse-plugin</artifactId> 
                        <version>2.9</version> <configuration> 
                        <downloadSources>true</downloadSources> 
                        <downloadJavadocs>true</downloadJavadocs> 
                        <wtpversion>2.0</wtpversion> 
                        <wtpContextName>spring3</wtpContextName> 
                </configuration> </plugin> -->
        </plugins>
        <finalName>UserManagement</finalName>
    </build>
</project>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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-4.0.xsd 
    http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <context:component-scan base-package="com.user.controller" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/jsps/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <mvc:annotation-driven />

</beans>
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

/WEB-INF/views/JSP/
.jsp
web.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.users</groupId>
    <artifactId>UserManagement</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>UserManagement Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <jdk.version>1.7</jdk.version>
        <spring.version>4.2.1.RELEASE</spring.version>
        <jstl.version>1.2</jstl.version>
        <servletapi.version>3.1.0</servletapi.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servletapi.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <!-- <plugin> 
                        <groupId>org.apache.maven.plugins</groupId> 
                        <artifactId>maven-eclipse-plugin</artifactId> 
                        <version>2.9</version> <configuration> 
                        <downloadSources>true</downloadSources> 
                        <downloadJavadocs>true</downloadJavadocs> 
                        <wtpversion>2.0</wtpversion> 
                        <wtpContextName>spring3</wtpContextName> 
                </configuration> </plugin> -->
        </plugins>
        <finalName>UserManagement</finalName>
    </build>
</project>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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-4.0.xsd 
    http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <context:component-scan base-package="com.user.controller" />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/jsps/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <mvc:annotation-driven />

</beans>
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

Web应用程序创建的原型
春天
org.springframework.web.servlet.DispatcherServlet
春天
/
index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>`enter code here`
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    ${hMessage}
    <br /> 
    ${wMessage}
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Hello</title>
</head>
<body>
    ${helloMessage}
    <br /> 
    ${welcomeMessage}
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>DaDheeChi</title>
</head>
<body>

    <a href="abc.html">Click here to read hello and welcome
        message </a>

    <br/>
    <form action="abc.do" method="get">
        <input type="submit" value="Click" />
    </form>
</body>
</html>

达迪奇


如果控制器返回到“hello1”,那么视图中只需要hello1.jsp,值是RequestMapping值的名称,那么是否有“单击”主题之一

若控制器返回到“hello1”,那个么视图中只需要hello1.jsp,并且值是RequestMapping值的名称,所以是否有“单击”主题之一

使用
addAttribute
而不是
put
放入
控制器中

  map.addAttribute("helloMessage", helloWorldMessage);  
  map.addAttribute("welcomeMessage", welcomeMessage);  
别忘了在jsp中启用EL。使用此代码启用它

<%@ page isELIgnored="false" %>

使用
添加属性
而不是
放入
控制器

  map.addAttribute("helloMessage", helloWorldMessage);  
  map.addAttribute("welcomeMessage", welcomeMessage);  
别忘了在jsp中启用EL。使用此代码启用它

<%@ page isELIgnored="false" %>


感谢all Preview,任何人都可以帮助我,因为我已经在这个问题上花了将近2天的时间,但我无法解决,如果在您单击
时出现这种情况,任何人都可以请您帮忙吗?是的,在这两种情况下都会发生感谢all Preview,请任何人都可以帮助我,因为我已经花了将近2天的时间处理这个问题,但我无法修复,如果在您单击
时出现这种情况,请任何人都可以吗?是的,在这两种情况下都会发生。对于这两种情况,我只从控制器返回相同的页面(hello1.jsp),并且还尝试了单击按钮(不带超链接),但是输出是相同的,因为我只从控制器返回相同的页面(hello1.jsp),并且还尝试了单击按钮(不带超链接),但是输出是sameThank you Priyamal在hello1.jsp中编写标记后,我得到了它,并且非常感谢(:非常感谢您在hello1.jsp中编写标记后,非常感谢您Priyamal)非常感谢