Struts2萬用字元詳解

2021-07-27 01:17:19 字數 2853 閱讀 8382

比如index.jsp裡有多個請求

href="<%=path %>/usersaction!add.action">adda>

href="<%=path %>/usersaction!show.action">showa>

href="<%=path %>/usersaction!update.action">updatea>

href="<%=path %>/usersaction!delete.action">deletea>

action裡面

package com.cj.action;

import com.opensymphony.xwork2.actionsupport;

public

class

usersaction

extends

actionsupport

public string show() throws exception

public string update() throws exception

public string delete() throws exception

}

struts.xml配置

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

用這種方式需要先開啟乙個開關 -->

name="struts.enable.dynamicmethodinvocation"

value="true" />

name="struts.devmode"

value="true">

constant>

name="struts.ui.theme"

value="******">

constant>

name="test"

extends="struts-default">

name="usersaction"

class="com.cj.action.usersaction"

method="add">

name="success">/index.jspresult>

action>

name="usersaction"

class="com.cj.action.usersaction"

method="show">

name="success">/index.jspresult>

action>

name="usersaction"

class="com.cj.action.usersaction"

method="update">

name="success">/index.jspresult>

action>

name="usersaction"

class="com.cj.action.usersaction"

method="delete">

name="success">/index.jspresult>

action>

package>

struts>

像xml這裡面有多個重複檔案,這裡就需要萬用字元

class="com.cj.action.usersaction" method="">

name="success">/index.jspresult>

就可以完成上面4種請求

但如果有多個action,上邊只有乙個使用者user的 ,如果再來乙個新聞的就還要加乙個

class="com.cj.action.usersaction" method="">

name="success">/index.jspresult>

name="newsaction"

class="com.cj.action.newsaction" method="">

name="success">/index.jspresult>

這又會出現兩個相似的,怎麼將這兩個相似的合併

在index.jsp裡面新增新聞的增刪該查

href="<%=path%>/newsaction!add.action">adda>

href="<%=path%>/newsaction!show.action">showa>

href="<%=path%>/newsaction!update.action">updatea>

href="<%=path%>/newsaction!delete.action">deletea>

struts.xml

將news和users用號替代 號代表所有 代表第乙個*號

class="com.cj.action.action" method="">

name="success">/index.jspresult>

index.jsp裡面請求位址也要相應變化

沒用萬用字元*

/usersaction!add.action">add

a>

使用萬用字元*

就得用類名替代

/usersaction!add.action">add

a>

進一步優化

_ 哪個類的哪個方法

class="com.cj.action.action" method="">

name="success">/index.jspresult>

jsp裡面

/news_add!add.action">add

a>

struts2 萬用字元用法

原理 用 來填充佔位符,出現的第乙個 對應,第二個 對應 例子 action name crud class example.crud method 當頁面中請求crud input.action時,就會自動去找action的input方法,當遇到crud delete時,就會自動去找action的...

Struts2萬用字元配置

name edit class org.apache.struts 萬用字元中幾個特殊的標記,如下所述 可以匹配0個或多個任意字元,但是不包括正斜槓 可以匹配0個或多個任意字元,包括正斜槓 在內 反斜槓,轉義字元。因為 不能匹配正斜槓,所以前面 editsubscription add不會被匹配上。...

struts2 萬用字元對映

小哥叫我閱讀專案伺服器端的 發現struts.xml中有 這個是什麼意思呢?name guestroommsg 代表這個action處理以guestroommsg 開頭的請求 入 guestroommsg getname 等 method 表示根據guestroommsg methodname 訪問...