一水空間
生命短暫,道也漫長(zhǎng)
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
隨筆-2 評(píng)論-0 文章-0 trackbacks-0
2009年12月15日
反射練習(xí)之a(chǎn)ction消除execute方法
/**
* @author yzy
* 作為BaseAction 供其他Action 繼承, 其他Action 不需要寫execute(mapping, form, request, response)
* 方法,直接寫與mapping.getParameter()[struts-xml 的<action> 中parameter] 對(duì)應(yīng)的 方法名(mapping, form, request, response)方法;
*
* 或者mapping.getPath()[struts-xml 的<action> 中path] 固定寫為 method_0,直接寫與mapping.getParameter()對(duì)應(yīng)的
* 方法名(String ... str)方法
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
actionForward = mapping.findForward("forward");
if("method_0".equals(mapping.getPath())){
method_0(mapping, form, request, response);
} else {
try {
// 正常Struts 方法名(ActionMapping mapping, ActionForm form,
// HttpServletRequest request, HttpServletResponse response)
this.getClass().getMethod(mapping.getParameter(), ActionMapping.class, ActionForm.class,
HttpServletRequest.class, HttpServletResponse.class).invoke(this, mapping, form, request, response);
} catch (Exception e) {
System.err.println("no serach method");
}
}
return actionForward;
}
/*
* 方法名(String ... str)
*/
private void method_0(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
String param = request.getQueryString();
String[] params = param.split("&");
int len = params.length;
Class[] classes = new Class[len - 1];
for(int i = 0; i < len; i++){
classes[i] = String.class;
}
try {
this.getClass().getMethod(mapping.getParameter(), classes).invoke(this, params);
} catch (Exception e) {
System.err.println("no serach method");
// str[] 可能參數(shù)個(gè)數(shù)不一致
}
}
posted @
2009-12-15 19:52
秒速4鍵 閱讀(309) |
評(píng)論 (0)
|
編輯
收藏
僅列出標(biāo)題
<
2025年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
常用鏈接
我的隨筆
我的評(píng)論
我的參與
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
struts(1)
隨筆檔案
2009年12月 (1)
文章分類
css
java
script
struts
搜索
最新評(píng)論
閱讀排行榜
1.?反射練習(xí)之a(chǎn)ction消除execute方法(309)
評(píng)論排行榜
1.?反射練習(xí)之a(chǎn)ction消除execute方法(0)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 秒速4鍵
主站蜘蛛池模板:
杨浦区
|
高台县
|
驻马店市
|
临泉县
|
鸡泽县
|
冷水江市
|
八宿县
|
库车县
|
华坪县
|
临朐县
|
股票
|
弥勒县
|
库尔勒市
|
嘉定区
|
巨野县
|
宝鸡市
|
瓮安县
|
称多县
|
和静县
|
陕西省
|
张掖市
|
班玛县
|
延庆县
|
蓝田县
|
平武县
|
南康市
|
天津市
|
东源县
|
肥东县
|
灵寿县
|
韶关市
|
江阴市
|
靖远县
|
阳朔县
|
壶关县
|
分宜县
|
钦州市
|
镇康县
|
昌都县
|
嘉峪关市
|
高尔夫
|