首页新闻找找看学习计划

jsp上显示不了ModelAndView的值

0
悬赏园豆:20 [已解决问题] 解决于 2018-08-06 20:48

不知道什么原因,在jsp上显示不了modelAndView的值

controller中的代码:

package com.zjm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/")
public class IndexController {
    @RequestMapping
    public ModelAndView index() {
        ModelAndView view=new ModelAndView("Index");
        view.addObject("welcome","hello");
        return view;
    }

}

jsp中的代码:

<%@ 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>Insert title here</title>
</head>
<body>
<h2>welcome to user SpringMVC</h2>
<h2>your welcome param:${welcome}</h2>
</body>
</html>

web.xml:

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1" >
    <!--定义了WEB应用的名字 -->
    <display-name>MyProject</display-name>
    <!-- 指定欢迎页 -->
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <!-- 配置Spring IOC容器 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 配置Springmvc的 DispatcherServlet -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!-- 配置编码方式过滤器.配置所有的过滤器的最前面 -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>
    <!-- 为了使用SpringMVC框架实现Rest风格,需配置hiddenHttpMethodFilter -->
    <filter>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>
</web-app>
复制代码

帮忙看下到底是哪里有问题,感谢啦!


jianming2032的主页 jianming2032 | 初学一级 | 园豆:104
提问于:2018-07-31 21:39
< >
分享
最佳答案
0

taglib标签没有吧

收获园豆:10
kin1492 | 菜鸟二级 |园豆:214 | 2018-07-31 22:36

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

kin1492 | 园豆:214 (菜鸟二级) | 2018-07-31 22:42

@kin1492: 谢谢,加进去了还是没有显示

jianming2032 | 园豆:104 (初学一级) | 2018-08-01 09:03
其他回答(2)
0

el表达式要显式地写出来

收获园豆:10
爱跑步的星仔 | 园豆:214 (菜鸟二级) | 2018-07-31 23:12

谢谢,麻烦说下要怎么显式写出来,刚学这个不会啊

支持(0) 反对(0) jianming2032 | 园豆:104 (初学一级) | 2018-08-01 09:07

@jianming2032: 

jsp中加上我下面标红的:忽略EL表达式为false,貌似,低版本的jsp是忽略EL表达式的。

支持(0) 反对(0) 爱跑步的星仔 | 园豆:214 (菜鸟二级) | 2018-08-01 09:41

@爱跑步的星仔: 这个我加过,还是没有,昨天晚上就百度过加上去试过了

支持(0) 反对(0) jianming2032 | 园豆:104 (初学一级) | 2018-08-01 15:06
0

配置问题,已经解决

jianming2032 | 园豆:104 (初学一级) | 2018-08-06 20:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册