为什么我的模型和视图对象未显示在JSP页面中? [英] Why my model and view object not displaying in JSP page .?
本文介绍了为什么我的模型和视图对象未显示在JSP页面中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用spring mvc.下面的代码示例.
Hi I am using spring mvc .Sample of code below here.
@Controller
public class WelcomeController {
@RequestMapping("/welcome")
public ModelAndView welcome() {
String message = "welcome to my tutorial";
return new ModelAndView("welcome", "message", message);
}
}
但是这里无法通过jsp页面获取此消息;
But here this message is not able to fetch by jsp page it is;
welcome.jsp
message:${message}
只有我收到消息: 没有显示任何错误消息.
Only i am getting message: Nothing is displaying for error messgge.
Here Web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Dispatcherspring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class><load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcherspring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
Here my Spring file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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="package-name" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
我都发布了xml和web.xml文件
Both xml and web.xml file i had post
推荐答案
My controller is
@Controller
public class HouseController {
@Autowired
private HouseService houseService;
@GetMapping(value = "/house")
public ModelAndView get() {
ModelAndView modelAndView = new ModelAndView();
List<HouseDto> listHouse = houseService.listHouse();
modelAndView.addObject("listHouse", listHouse);
modelAndView.setViewName("house/listHouse");
return modelAndView;
}
}
<%@ page contentType="text/html; charset=UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page contentType="text/html; charset=UTF-8" isELIgnored="false"%>
###JSP
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>
<c:forEach var="house" items="${listHouse}" varStatus="">
<tr>
<td>${house.name}</td>
</tr>
</c:forEach>
</div>
<body>
#<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
its work for me
这篇关于为什么我的模型和视图对象未显示在JSP页面中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文