-1

コードがURLを再フォーマットし、次のように表示することを期待しています(with /)

 http://www.example.com/myProject/Profile/view.action
 http://www.example.com/myProject/Profile/edit.action

しかし、それはそれらを次のように示します(_付き)

http://www.example.com/myProject/Profile_view.action
http://www.example.com/myProject/Profile_edit.action

そのために、struts.xmlファイルの「_」を「/」に変更しましたが、機能しません。

<action name="Profile/*" method="{1}" class="com.controller.Profile">
      <result name="view" tiles="viewProfile">viewProfile</result>
       <result name="edit" tiles="editProfile">editProfile</result>
  </action>

私は次のコードを使用してそれを呼んでいます

 <a href="Profile/view.action" >Profile</a>

それを実装する他の方法があるかどうか私に知らせてください。

4

3 に答える 3

1

アクションをスラッシュで本当に区切りたい場合は、次を使用NAMESPACEしてください。

<package name="profile" extends="struts-default" namespace="/Profile">
    <action name="*" method="{1}" class="com.controller.Profile">
      <result name="view" tiles="viewProfile">viewProfile</result>
      <result name="edit" tiles="editProfile">editProfile</result>
    </action>
</package>

また、URLでパラメータを使用しようとしている場合は、使用を検討する必要があります

<constant name="struts.enable.SlashesInActionNames" value="true"/>

Struts2構成ファイルにあります。

Wildcart Mappingドキュメントに関しては、次のこともできます。

    <action name="**" method="{1}" class="com.controller.Profile">
      <result name="view" tiles="viewProfile">viewProfile</result>
      <result name="edit" tiles="editProfile">editProfile</result>
    </action>

** matches zero or more characters including the slash ('/') character.これは、 Wildcartマッピングドキュメントでも見つけることができ ます。

最初に本当に必要なものを考えてから、構成と実装を行う必要があります。

あなたの場合、Struts 2は、アクション構成に関して、アクションにスラッシュがあると見なします

スラッシュ付き
のアクション名アクション名にスラッシュが含まれている場合(たとえば <action name="admin/home" class="tutorial.Admin"/>)、struts.xmlファイルの定数を使用して、を指定することにより、アクション名にスラッシュを明確に許可する必要があります <constant> name="struts.enable.SlashesInActionNames" value="true"/>
このプロパティをtrueに設定すると副作用があるため、説明についてはJIRAIssueWW-1383を参照してください。

ドットとダッシュを使用したアクション名 アクションの名前付けは非常に柔軟ですが、ドット(例)やダッシュ(例)
を使用する場合は注意が必要です。現時点では、ドット表記には既知の副作用はありませんが、ダッシュ表記は、特定のタグおよびテーマに対して生成されたJavaScriptで問題を引き起こします。注意して使用し、常にキャメルケースのアクション名(例 )またはアンダースコア(例)を使用するようにしてください。create.usermy-actioncreateUsermy_action

したがって、Struts2はスラッシュをアンダースコアに変換します。

于 2013-02-14T08:50:33.523 に答える
1

なぜあなたの行動を次のように呼んでいるのですか

<a href="Profile/view.action" >Profile</a>

ただし、これを使用してこれを達成できます

<a href="view.action" >Profile</a>

xmlに変更を加えました

<action name="view.action" method="{1}" class="com.controller.Profile">
      <result name="view" tiles="viewProfile">viewProfile</result>
       <result name="edit" tiles="editProfile">editProfile</result>
</action>

アクションで何も指定していないため、method="{1}"のマッピングでここでワイルドカードを使用することは許可されていません。ワイルドカードを本当に使用したい場合は、次のようにアクションでメソッド名を指定します

<a href="YOURMETHODNAMEview.action" >Profile</a>

そしてあなたのxmlで

 <action name="*view.action" method="{1}" class="com.controller.Profile">
          <result name="view" tiles="viewProfile">viewProfile</result>
           <result name="edit" tiles="editProfile">editProfile</result>
    </action>
于 2013-02-14T05:56:01.070 に答える