如何利用反射机制实现前台页面共用一个servlet文件
2016-04-29 19:15
766 查看
背景:当前台页面需要共用一个servlet的时候,这个时候可以在servlet的doGet方法中根据不同的页面调用servlet定义的不同方法
例如,前台页面中设置<a href=“servlet?method=xaiojie”></a>
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String methodname=request.getParameter("method"); try { Method method=getClass().getDeclaredMethod(methodname,HttpServletRequest.class,HttpServletResponse.class); method.invoke(this, request,response);//调用各自的方法 } catch (Exception e) { e.printStackTrace(); } }
protected void xiaojie(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
<span style="white-space:pre"> </span>……
}
相关文章推荐
- bzoj 1858: [Scoi2010]序列操作
- POJ 3270 置换群
- LightOJ - 1374 Confusion in the Problemset (模拟)
- mysql 变量
- ThinkPHP单字母函数汇总
- 反射
- 冲刺第十天
- 1.项目大致架构设计
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- Scrum 团队成立 -- 软件工程
- hdu-1285拓扑排序
- 冲刺7
- MAC卸载/删除 Parallels Desktop虚拟机的方法
- 【7】Zabbix WEB指标监控
- Java 内部类的一些总结
- 实验十一 路由器综合路由配置
- 无线网卡工作模式笔记
- 解决安装pycrypto时的错误:Unable to find vcvarsall.bat
- 欢迎使用CSDN-markdown编辑器
- 虚拟机VirtualBox安装遇见问题