如何分开头?

时间:2013-12-05 13:36:53

标签: jsf templating jspx

这里看看我的.jspx文件:

<?xml version='1.0' encoding='utf-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core">
     <jsp:output omit-xml-declaration="true"  doctype-root-element="HTML" doctype-system="http://www.w3.org/TR/html5"/>
    <jsp:directive.page contentType="text/html;charset=utf-8"/>
    <f:loadBundle basename="my.pack.resource" var="r"/>
    <f:loadBundle basename="my.pack.error" var="e"/>
    <f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html utf-8"/>
            <meta name="viewport" content="width=device-width"/>
            <title> Some title </title>
            <jsp:directive.include file="/temp/myLayout.jspf" />            
        </head>


        <body>

            <h:form>            

                <h:commandLink .........

                </h:form>

        </body>


        </html>
    </f:view>
</jsp:root>

为了让我的视图文件清晰而小巧 我想将所有置于正文之后 模板并将其包含在我的.ispx文件中,并将title作为参数传递。

如果有人知道解决方案,请帮助。

修改 我已将我的视图从.jspx更改为.xhtml,但我的servlet过滤器现在不起作用。 这是我的web.xml:

   <?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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"
         version="2.5">
    <context-param>
        <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
        <param-value>*.xhtml;*.jsf</param-value>
    </context-param>
    <filter>
        <filter-name>loginFilter</filter-name>
        <filter-class>my.pack.filterpack.LoginFilter</filter-class>
    </filter>
    <filter>
        <filter-name>remebermefilter</filter-name>
        <filter-class>my.pack.filterpack.RemeberMeFilter</filter-class>
    </filter>
    <filter>
        <filter-name>NoCacheFilter</filter-name>
        <filter-class>my.pack.filterpack.NoCacheFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>loginFilter</filter-name>
        <url-pattern>/view/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>remebermefilter</filter-name>
        <url-pattern>/login/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>NoCacheFilter</filter-name>
        <url-pattern>*.xhtml</url-pattern>                
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>


    <!-- servlet mappings -->

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>


    <error-page>
        <error-code>500</error-code>
        <location>/index.jsp</location>
    </error-page>
    <error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/viewExp.jsp</location>
    </error-page>
    <listener>
        <listener-class>my.pack.timer.MyJobManager</listener-class>
    </listener>
</web-app>

1 个答案:

答案 0 :(得分:1)

这就是为什么JSP(X)在4年前被Facelets放弃,弃用和成功的原因之一。 JSP(X)不提供简单的模板功能以实现这种要求。

只需迁移到Facelets。将.jspx重命名为.xhtml,并将<jsp:xxx>标记替换为<ui:xxx>个标记。您的功能需求在How to include another XHTML in XHTML using JSF 2.0 Facelets?

的第二个示例中得到了解答

Facelets在JSF 2.x中原生可用。如果您仍在使用JSF 1.x,那么您可以按照its documentation单独安装它。