【问题标题】:apache tiles not rendering correctly (shows plain text) in struts2struts2 中的 apache 瓦片未正确呈现(显示纯文本)
【发布时间】:2013-07-29 09:39:29
【问题描述】:

我正在使用 Apache tiles2 框架开发一个 struts2 Web 应用程序。 该代码在 localhost 上运行良好,但是当我在服务器上启动代码时,它会将平铺页面呈现为纯文本。谁能告诉我问题出在哪里。 我的意思是说页面在浏览器端显示为纯文本。

这是它在浏览器中的呈现方式。截图 - http://i42.tinypic.com/2vnj686.jpg

如果有人有解决方案,请帮助我......

这是我的tiles.xml

    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE tiles-definitions PUBLIC
           "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
           "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"  >
    <!--        "http://tiles.apache.org/dtds/tiles-config_2_1.dtd" -->
    <tiles-definitions>

        <definition name="BaseDef" template="/adminpanel/template/BaseLayout.jsp">

            <put-attribute name="title" value="Home Page" />
            <put-attribute name="css" value="/adminpanel/template/extracss.jsp" />
            <put-attribute name="js" value="/adminpanel/template/js.jsp" />
            <put-attribute name="header" value="/adminpanel/template/header.jsp" />
            <put-attribute name="body" value="/adminpanel/template/body.jsp" />
            <put-attribute name="footer" value="/adminpanel/template/footer.jsp" />

    </definition>

        <definition name="LatestMaterial" extends="BaseDef">
            <put-attribute name="title" value="Latest Exam Material " />
            <put-attribute name="css" value="/adminpanel/template/newtablecss2.jsp" />              
            <put-attribute name="body" value="/adminpanel/Pages/latestexammaterial.jsp" />
            </definition>
    </tiles-definitions>

这是我的 BaseLayout.jsp

        <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"%>
        <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="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>

        <tiles:insertAttribute name="css"/>
        <tiles:insertAttribute name="js"/>
         <title><tiles:insertAttribute name="title" /></title>
        </head>
        <body>

            <div id="main">
                        <tiles:insertAttribute name="header"/>
                                        <div id="body">
                                                 <tiles:insertAttribute name="body"/>
                                        </div></div>
                        <tiles:insertAttribute name="footer"/>

        </body>
        </html>

这就是我在 struts.xml 中使用它的方式

   <package name="wz.admin"  extends="struts-default,json-default,tiles-default">
      <action name="LatestMaterial" class="org.wz.admin.LatestMaterialAction">
        <result type="tiles">LatestMaterial</result>
    </action>
    </package>

【问题讨论】:

  • 您的 CSS 是否正确导入?您是否检查过/adminpanel/template/extracss.jsp 页面的 HTML 渲染部分是否正确指向您的 CSS?
  • 是的,我交叉检查了它..它是正确导入的..即使它不是它应该至少显示一些没有css而不是纯文本的奇怪html页面..不是吗?
  • 控制台有异常吗?
  • 没有例外...根据tomcat一切都很好..
  • 看看这个Example。您是否在web.xml 中正确配置了部署描述符和磁贴侦听器?

标签: html struts2 tiles


【解决方案1】:

我重新检查了您的代码,我认为问题出在您的 struts.xml 上,因为一切看起来都很好。我不确定 100%,但请尝试将您的 struts.xml 更改为:

    <package name="wz.admin" extends="struts-default" namespace="/">
        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>
        <action name="LatestMaterial" class="org.wz.admin.LatestMaterialAction">
            <result type="tiles">LatestMaterial</result>
        </action>
    </package>

此外,即使success 结果是默认结果,您也应该为结果命名以避免在管理多个结果时产生误解:

    <result name="success" type="tiles">LatestMaterial</result>

这只是我的建筑师在我使用 struts 时给我的一个建议。最后我发现它真的很有用。

【讨论】:

  • success 结果是默认值。
  • @AleksandrM 我知道success 是默认结果,但这只是我当时的架构师给我的建议,当我努力使用struts 时,我发现它很有用。
  • 您可以将其包含在您的答案中。
  • 感谢@araknoid 的支持.. 昨天我找到了解决这个问题的方法...我正在使用带有 2.0.6 版瓷砖的 struts 2.3.8 ..实际上我想说我正在使用与 struts 2.3.8 软件包一起提供的相同文件..但昨天我下载了一个新的 struts tile 插件,即 2.3.16 并将其与 tile 2.0.6 一起使用,这就像一个魅力..我不知道为什么我遇到了这个问题,因为如果它与包装一起发货,它应该可以正常工作...感谢 araknoid 的努力并感谢其他人的尝试...
猜你喜欢
  • 2021-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多