设为首页 加入收藏

TOP

Struts2动态调用DMI及错误解决方法
2015-07-16 12:57:06 来源: 作者: 【 】 浏览:11
Tags:Struts2 动态 调用 DMI 错误 解决 方法

在Strust2中action可以定义自己的方法,调用方法有两种方式,一种方式是struts.xml中指定method来表示需要用到的方法,但是这种方法缺点在于如果你的Action中有很多方法则要多次配置,这样很繁琐,另一种方法是使用动态方法调用DMI。


举一个简单的例子——


比如LoginAction中有add,dell方法,则


1、配置struts.xml文件


1
2? ? ?
3? ? ? ? ? ? /add.jsp
4? ? ? ? ? ? /dell.jsp
5? ? ?

6


2、在 loginAction中 编写add方法和dell方法:


public? String? add()
{
? return "add";
}
public? String dell()
{
? return "dell";
}


3、链接中使用!动态调用所需方法:


调用add方法
调用dell方法



常见错误:


?There is no Action mapped for namespace [/XXX] and action name [xxx!xxx] associated with context path [/xxx_method].?


解决方法:


?默认的Struts.xml中是这样的



?这样我们在地址栏输入感叹号动态调用方法的时候会出错,我们只需更改这一句即可


?


??


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇struts2完全捕获404错误的方法 下一篇Django中如何生成非HTML格式的内容

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: