gpt4 book ai didi

java - SpringMvc 磁贴不显示页眉和页脚

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:22 24 4
gpt4 key购买 nike

在我的元素中,我有tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

<definition name="base.definition" template="/WEB-INF/layoutStyle/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/layoutStyle/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/layoutStyle/footer.jsp" />


</definition>

<definition name="home" extends="base.definition">
<put-attribute name="title" value="home" />
<put-attribute name="body" value="/WEB-INF/jsp/home.jsp" />

</definition>


</tiles-definitions>

spring-servlet.xml 是:--

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.1.xsd">

<context:annotation-config />
<mvc:annotation-driven />
<context:component-scan base-package="com.patra.news" />

<mvc:default-servlet-handler />
<mvc:resources mapping="/resources/**" location="/resources/" />

<bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:order="0" p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView"
p:viewNames=".*" />

<bean id="jstlViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="1" p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

<!-- Tiles Configuration -->

<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>

</beans>

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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>

</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

layout.jsp 是:--

<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>

<link rel="stylesheet" href="<c:url value="resources/css/screen.css" />" type="text/css" media="screen, projection"></link>
<link rel="stylesheet" href="<c:url value="resources/css/print.css" />" type="text/css" media="print"></link>


<%--
<link href="<c:url value="/resources/main.css" />" rel="stylesheet">
<script src="<c:url value="/resources/jquery.1.10.2.min.js" />"></script> --%>

<style>
body{ margin-top:20px; margin-bottom:20px; background-color:#DFDFDF;}
</style>

</head>


<body>
<div class="container" style="border: #C1C1C1 solid 1px; border-radius:10px;">
<!-- Header -->
<tiles:insertAttribute name="header" />
<!-- Body Page -->
<div class="span-19 last">
<tiles:insertAttribute name="body" />
</div>
<!-- Footer Page -->
<tiles:insertAttribute name="footer" />
</div>

</body>
</html>

header.jsp 是:--

<div class="span-24">
<img src="resources/images/logo.png"
width="90" style="padding-top:10px;" />
</div>

footer.jsp 是:--

<hr />
<div class="span-1 prepend-3">&nbsp;</div>
<div class="span-16 last">
<p>
<b>TechZoo - A Zoo of Technology</b>
( All rights Reserved)
</p>
</div>

home.jsp 是:--

<%@page language="java" contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!-- <link rel="stylesheet" href="resources/css/header_style.css" type="text/css" media="print"></link> -->

<link rel="stylesheet" href="resources/css/navstyle.css" type="text/css" media="print"></link>


<style>
table.reference tr:nth-child(even) {
background-color: #ffffff;
border: 1px solid #000;
}
tbody {
display: table-row-group;
vertical-align: middle;
border-color: inherit;
}
table.reference tr:nth-child(odd) {
background-color: #f1f1f1;
}
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
}
</style>
<div style="margin: 10px;">
<h4>List of Persons</h4>
<table style="width: 600px" class="reference">
<tbody>
<tr>
<th>Sr. No.</th>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
</tbody>
</table>
</div>

index.jsp 是:--

<jsp:forward page="home.htm"/>

但是当我运行元素时,它只显示正文..不添加页眉和页脚..我无法理解我在哪里放置了错误的代码..请建议我..

最佳答案

我不熟悉tiles 2.2,但我建议您使用版本3

POM

<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>

<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.5</version>
</dependency>

tiles.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

spring-servlet.xml

<bean id="tilesViewResolver" 
class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>

删除其他解析器

<bean id="jstlViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="1" p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

关于java - SpringMvc 磁贴不显示页眉和页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31461037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com