是否有可能将jspf文件添加到jsp页面而不使用jsp:include? [英] Is it possible to add jspf files to a jsp page without using jsp:include?

查看:175
本文介绍了是否有可能将jspf文件添加到jsp页面而不使用jsp:include?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现的是类似于asp.net中的母版页。我遵循教程,但我可能错过了一些东西,因为我已经将我的header.jspf和footer.jspf添加到WEB-INF / jspf文件夹中,而index.jsp位于WEB-INF之外。我在web.xml中添加了信息,以便某些jsp页面应该自动添加页眉和页脚。问题可能是index.jsp无法访问WEB-INF文件夹内的任何内容,但我认为我已经在教程的前一步中解决了这个问题。当我运行该项目时,我得到的是index.jsp剩下的所有页眉和页脚内容。



我不想使用:<%@ include file =header.jspf%> < .. jsp:include ...>

屏幕截图:



web.xml:

 <?xml version =1.0encoding =UTF-8?> 
< web-app version =3.0
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的/网络app_3_0.xsd>
< session-config>
< session-timeout>
30
< / session-timeout>
< / session-config>
< jsp-config>
< jsp-property-group>
< description>页眉和页脚设置< / description>
< url-pattern> /index.jsp< / url-pattern>
< url-pattern> / WEB-INF / view / *< / url-pattern>
< include-prelude> /WEB-INF/jspf/header.jspf< / include-prelude>
< include-coda> /WEB-INF/jspf/footer.jspf< / include-coda>
< / jsp-property-group>
< / jsp-config>
< / web-app>

header.jspf:

 <%@ page contentType =text / htmlpageEncoding =UTF-8%> 
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>网上商店< / title>
< / head>
< body>
< h1>网上商店< / h1>

footer.jspf:

 < / body> 
< / html>


解决方案

我也在做这个教程,使用Tomcat作为服务器,它不会包含页眉和页脚,我必须使用glassfish服务器,有没有办法让tomcat包含页眉和页脚?



编辑:



使用这个替换默认标签似乎已经解决了使用tomcat作为服务器的问题

 < web-app xmlns =http://java.sun.com/xml/ns/j2ee
xmlns:xsi =http:// www .w3.org / TR / xmlschema-1 /
xsi:schemaLocation =http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsdversion =2.4>


What I want to achieve is something similar to a master page in asp.net. I'm following a tutorial, but I may have missed something cause I have added my header.jspf and footer.jspf to the WEB-INF/jspf folder and index.jsp is outside of WEB-INF. I have added info in web.xml so that certain jsp-pages should automatically add the header and footer. The problem might be that index.jsp can't access anything inside the WEB-INF folder, but I thought I had solved that in a previous step in the tutorial. When I run the project, all I get is what's left of index.jsp after I remove all the header and footer stuff.

I don't want to use: <%@include file="header.jspf" %> and <..jsp:include...>.

Screenshot:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    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_3_0.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <jsp-config>
        <jsp-property-group>
            <description>header and footer settings</description>
            <url-pattern>/index.jsp</url-pattern>
            <url-pattern>/WEB-INF/view/*</url-pattern>
            <include-prelude>/WEB-INF/jspf/header.jspf</include-prelude>
            <include-coda>/WEB-INF/jspf/footer.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>
</web-app>

header.jspf:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Webshop</title>
</head>
<body>
     <h1>Webshop</h1>

footer.jspf:

</body>
</html>

解决方案

I'm also doing that tutorial, and when I use Tomcat as the server it won't include the header and the footer, I have to use the glassfish server, is there any way to make tomcat include the header and the footer?

EDIT:

Replacing the default tag with this one seems to have solved the problem using tomcat as the server

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/TR/xmlschema-1/"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

这篇关于是否有可能将jspf文件添加到jsp页面而不使用jsp:include?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆