java - 如何确定 JSP 页面使用哪个 Tile 定义?

标签 java apache jsp struts tiles

我对 Java 还很陌生,刚刚遇到了一个奇怪的问题。以前,一切都工作正常,我不知道我做了什么把它搞砸了(我知道,每个人都这么说)。发生的情况是,我正在开发一个使用 Apache Struts (1.x) 和 Tiles 的 Web 应用程序,当我在 Web 浏览器中转到某个页面时,它似乎使用了与以前不同的 Tile 定义。

以下是tiles-config.xml 中的相关行:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration//EN"
       "http://supplies.ur.com/dtds/tiles-config_1_1.dtd">

<tiles-definitions>
  <definition name=".default" path="/template_new.jsp">
    <put name="title" value="[Company Web App Name]" direct="true"/>
    <put name="customerInfo" value="/customerInfo.jsp" direct="false"/>
    <put name="smallBody" value="" direct="true"/>
    <put name="menu" value="" direct="true"/>
    <put name="quickMenu" value="/quickMenu.jsp" direct="false"/>
    <put name="adminMenu" value="/adminMenu.jsp" direct="false"/>
    <put name="message" value="/message.jsp" direct="false"/>
    <put name="body" value="" direct="true"/>
    <put name="helpAvailable" value="yes" direct="false"/>
    <put name="feedbackAvailable" value="yes" direct="false"/>
    <put name="problemReportingAvailable" value="yes" direct="false"/>
    <put name="newFeaturesAvailable" value="yes" direct="false"/>
  </definition>
  <definition name=".empty" path="/blank.jsp">
    <put name="title" value="[Company Web App Name]" direct="true"/>
    <put name="customerInfo" value="/customerInfo.jsp" direct="false"/>
    <put name="quickMenu" value="/quickMenu.jsp" direct="false"/>
    <put name="message" value="/message.jsp" direct="false"/>
    <put name="body" value="" direct="true"/>
    <put name="footer" value="/footer2.jsp" direct="false"/>
    <put name="helpAvailable" value="yes" direct="false"/>
    <put name="feedbackAvailable" value="yes" direct="false"/>
    <put name="problemReportingAvailable" value="yes" direct="false"/>
    <put name="newFeaturesAvailable" value="yes" direct="false"/>
  </definition>
  <!-- Forgot to include the .rentalHistoryByType definition... -->
  <definition name=".rentalHistoryByType" extends=".default">
    <put name="title" value="Equipment Rental History By Type" direct="true"/>
    <put name="smallBody" value="/rentalHistoryByType_Search.jsp" direct="false"/>
    <put name="body" value="/rentalHistoryByType.jsp" direct="false"/>
  </definition>
  <!-- Added for CoolBeans -->
  <definition name=".customerChoose" extends=".default">
    <put name="title" value="Choose a customer" direct="true"/>
    <put name="quickMenu" value="" direct="true"/>
    <put name="smallBody" value="/customerChoose_Search.jsp" direct="false"/>
    <put name="body" value="/customerChoose.jsp" direct="false"/>
  </definition>
</tiles-definitions>

以下是 struts-config.xml 中的相关行:

<action path="/rentalHistoryByType" type="com.[company name deleted].etrieveit.actions.RentalHistoryByTypeAction">
  <forward name="customerNotSelected" path="/customerChoose.do" />
  <forward name="success" path=".rentalHistoryByType" />
</action>
<!-- Added for CoolBeans -->
<action path="/customerChoose" type="com.[company name deleted].etrieveit.actions.CustomerChooseAction">
  <forward name="success" path=".customerChoose" />
</action>

我要在浏览器中访问的页面是“[path]/rentalHistoryByType.do”,其主体是使用rentalHistoryByType_Search.jsp 和rentalHistoryByType.jsp 构建的。我发现问题的方式是 jQuery 突然停止在页面上工作,而之前它工作得很好。在查看源代码时,我发现rentalHistoryByType.do是从blank.jsp构建的,而不是template_new.jsp。 (template_new.jsp 包含 jQuery 脚本,而空白.jsp 则没有,并且页面源代码中的其他详细信息也与空白.jsp 完全匹配。)

我的问题是,如何知道页面在收到请求时将使用哪个 Tile 定义以及如何更改它?和/或,什么可能导致页面使用与之前明显使用的不同的 Tile 定义?

抱歉,如果我的术语错误或令人困惑,我对 Java 还很陌生,我还不知道自己在做什么......

最佳答案

应该有一个 struts 配置文件(通常名为 struts-config.xml),其中包含操作到定义的映射,例如它会包含

<action path="/home"
  type="com.myco.MyHomeAction">
  <forward name="home/landing"
    path="home.definition"/>
</action>

关于java - 如何确定 JSP 页面使用哪个 Tile 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4672242/

相关文章:

java - 在 run() 中中断当前线程不会抛出 InterruptedException

java - 应该在 applicationContext 和 dispatcherServlet 中声明哪些 beans

apache - hadoop.mapred vs hadoop.mapreduce?

在配置了代理的环境下运行的 Java 小程序(企业网络)

java - 如何在 JSTL 中使用 session ?

mysql - java EE Hibernate 列表多对多配置错误

java - 如何在jsp中格式化字符串?

java - Java和数据库中的多线程

django - Apache 不会以错误开始

javascript - 如果任一输入字段已填写,如何验证表单?