不知道什么原因,在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>
帮忙看下到底是哪里有问题,感谢啦!
taglib标签没有吧
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
@kin1492: 谢谢,加进去了还是没有显示
el表达式要显式地写出来
谢谢,麻烦说下要怎么显式写出来,刚学这个不会啊
@jianming2032:
jsp中加上我下面标红的:忽略EL表达式为false,貌似,低版本的jsp是忽略EL表达式的。
@爱跑步的星仔: 这个我加过,还是没有,昨天晚上就百度过加上去试过了
配置问题,已经解决