-1

要求されたリソースに応じて複数のデコレータを適用したいサイトメッシュ 2.4 プラグインを使用して、Struts 2 アプリケーションを作成しています。

decorators.xml

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
<decorator name="layout1" page="layout1.jsp">
    <pattern>/first/*</pattern>
</decorator>
<decorator name="layout" page="layout.jsp">
    <pattern>/second/*</pattern>
</decorator>
 </decorators>

デコレータディレクトリ内にlayout.jspとlayout1.jspという名前の2つの異なるレイアウトファイルを作成し、このようなナビゲーションファイルを作成しました

<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> 
<decorator:usePage id="thePage" /> 
<html>
<head>
</head>
<body>
<% String selection = thePage.getProperty("meta.selection"); %> 
<p> 
<table border="0" cellpadding="0" cellspacing="0"> 
<tr> 
    <td> 
        <% if(selection != null && "index".equals(selection)){ %> 
            <a href="first/index.jsp" class="selected">Main</a>
            <%System.out.println(""+selection); %> 
        <% } else { %> 
            <a href="first/index.jsp">Main</a> 
            <%System.out.println("index else"+selection); %>
        <% } %> 
    </td> 

</tr><tr> 
    <td> 
        <% if(selection != null && "page1".equals(selection)){ %> 
            <a href="second/page1.jsp" class="selected">Page 1</a> 
        <% } else { %> 
            <a href="second/page1.jsp">Page 1</a> 
        <% } %> 
    </td> 
</tr>
</table> 


ウェルカム ページ (/first/index.jsp) は、layout1 デコレータで表示され、「ページ 1」リンクをクリックすると、対応する (レイアウト) デコレータも表示されます。しかし問題は、「ページ 1」にアクセスした後にメイン リンクをクリックすると、「HTTP ステータス 404 - /StrutsSitemesh/second/first/index.jsp」が表示され、要求されたリソースが以前のリソース ディレクトリに追加されることです。動作するように助けてください

4

1 に答える 1

0

アプリケーションのコンテキストパスを返し、このような絶対パスでリソースを要求するすべてのリンク内で reqest.getContextPath() メソッドを使用しています----

<table border="0" cellpadding="0" cellspacing="0"> 
<tr> 
<td> 
    <% if(selection != null && "index".equals(selection)){ %> 
        <a href="<%=request.getContextPath() %>/first/index.jsp 
  class="selected">Main</a>
        <%System.out.println(""+selection); %> 
    <% } else { %> 
        <a href="<%=request.getContextPath() %>/first/index.jsp">Main</a> 
        <%System.out.println("index else"+selection); %>
    <% } %> 
</td> 
</tr>
<tr> 
<td> 
    <% if(selection != null && "page1".equals(selection)){ %> 
        <a href="<%=request.getContextPath() %>/second/page1.jsp"
 class="selected">Page 1</a> 
    <% } else { %> 
        <a href="<%=request.getContextPath() %>/second/page1.jsp">Page 1</a> 
    <% } %> 
</td> 
</tr>
</table> 

もっと生産的で効果的な解決策がある場合は、詳しく説明してください。

于 2013-05-14T11:45:43.357 に答える