Struts1.x系列教程(21):操纵MappingDispatchAction类调用差别[Java编程]
本文“Struts1.x系列教程(21):操纵MappingDispatchAction类调用差别[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
与LookupDispatchAction、DispatchAction差别,MappingDispatchAction类并不通过恳求参数来指定行动,而是将一个Struts行动对应于一个Action办法.下面的例子演示了若何利用MappingDispatchAction类来将Struts行动和Action办法相对应.
Action类的实现代码:
package action;
import org.apache.struts.actions.MappingDispatchAction;
……
public class MyMappingDispatchAction extends MappingDispatchAction
{
public ActionForward pdf(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
// 生成pdf文件
}
public ActionForward html(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
// 生成html文件
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
// 处理默许行动
}
}
上面的代码有两个Action办法:pdf和html,辨别用来生成pdf和html文件.还有一个unspecified办法用来处理默许行动.
我们可以利用以下的代码来配置MyMappingDispatchAction类:
<action path="/pdf" type = "action.MyMappingDispatchAction" parameter="pdf" />
<action path="/html" type = "action.MyMappingDispatchAction" parameter="html" />
可以通过以下的URL来拜候pdf和html行动,辨别会调用MyMappingDispatchAction类的pdf和html办法:
http://localhost:8080/samples/pdf.do
http://localhost:8080/samples/html.do
以上是“Struts1.x系列教程(21):操纵MappingDispatchAction类调用差别[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |