Jforum创建Action
来源:互联网 发布:二手房交易数据哪里查 编辑:程序博客网 时间:2024/06/05 16:16
JForum展示层介绍
JForum论坛没有使用主流的MVC框架,而是自己实现了一套简单的MVC框架。
JForum的MVC框架和现在流行的Struts2一样,使用了与web容器松耦合的设计,并没有直接为用户暴露 HttpServletRequest和HttpServletResponse接口,而是提供了 net.jforum.context.RequestContext和net.jforum.context.ResponseContext这两个接口,与Struts2不同的是JForum的action还是需要继承net.jforum.Command这个对象,并非一个简单的POJO。
JForum页面显示并没有使用JSP,而是使用freemarker的模板,框架本身与freemarker耦合在了一起,并非像Struts2可以灵活的替换显示方式。
基本开发流程
开发JForum的Action非常简单,首先我们要从几个方面入手。
1.建立action
新建一个类继承与net.jforum.Command
package net.jforum.view.test;import net.jforum.Command;import net.jforum.JForumExecutionContext;import net.jforum.util.preferences.TemplateKeys;public class TestAction extends Command{public void list(){} public void show(){ this.setTemplateName(TemplateKeys.TEST_SHOW); this.context.put("title", request.getParameter("title")); this.context.put("description", request.getParameter("description")); }}
2.注册action
到JForum的WEB-INF/config目录找到modulesMapping.properties ,在里面配置一个模块名称和对应的类
如:test=net.jforum.view.test.TestAction
3.注册模板
到JForum的WEB-INF/config目录找到templatesMapping.properties
在里面配置一个模板名称对应一个具体的显示页面(页面默认都要放在templates/default目录下)
如:test.show= test_show.htm
修改net.jforum.util.preferences.TemplateKeys类
在里面配置常量
如:
public static final String TEST_SHOW = "test.show";
4.TestAction类中新建方法 (如上所示)
- public void show()<BR>
- {<BR>
- //选择显示模板<BR>
- this.setTemplateName(TemplateKeys.TEST_SHOW);<BR>
- //组装模板变量<BR>
- this.context.put("title", request.getParameter("title"););<BR>
- this.context.put("description", request.getParameter("description"););<BR>
- }
public void show(){//选择显示模板this.setTemplateName(TemplateKeys.TEST_SHOW);//组装模板变量this.context.put("title", request.getParameter("title"););this.context.put("description", request.getParameter("description"););}
5.配置参数映射
到JForum的WEB-INF/config目录找到urlPattern.properties
在里面配置参数
如:test.show.2 = title, description
模块名称.方法名称.方法参数个数=参数1名称,参数2名称
6.创建test_show.htm(放在templates/default目录下)
<html><head><title>动作,参数测试页!</title></head>
<body>
动作,参数测试页
<br>
title=$ {title}<br>
description=$ {description}
7.运行
编辑header.htm页面添加如下代码,添加“我的测试”超级连接
<a id="latest2" class="mainmenu" href="$ {JForumContext.encodeURL("/test/show/arg1/arg2")}">我的测试</a>
或直接访问:
http://localhost:8080/jforumTest/test/show/arg1/arg2.page
运行结果:
这里说一下JForum的url的解析方式,这里举个例子:
http://localhost:8080/jforumTest/test/show/arg1/arg2.page
这个Url的实际含义是:
http://localhost:8080/jforumTest/模块名称/方法名称/参数1/参数2.page
modulesMapping.properties 中的配置:
test=net.jforum.view.test.TestAction
这里的test就是模块名称
urlPattern.properties 中的配置:
test.show.2 = title, description
这里的title和description就是参数1和参数2
之后在action中通过
request.getParameter("description");
request.getParameter("title");
可以取得它们的值
小结:
在JForum中建立一个action应该说还是比较容易的,在这里它选用freemarker做为显示方式想必也是为了方便美工编辑和美化模板,毕竟对于美工来讲htm编辑起来绝对是比jsp来的方便的。
- Jforum创建Action
- Jforum学习研究--编写action
- JForum
- jforum
- 最为详尽的Jforum的action开发文章
- 创建Action
- Tomcat+Mysql+Jforum创建论坛,Oray动态域名管理
- jforum配置
- jforum安装
- JForum论坛
- JForum研究
- jforum学习心得
- jforum搭建
- 创建Struts2的Action
- 创建Struts2的Action
- 创建action/service
- struts2下三种方式创建action
- 第十九篇 zabbix创建Action
- Repeater导出EXCEL 文本格式的解决方案
- 编译器、连接器学习笔记--(一)--综述
- 详细介绍Linux shell脚本基础学习
- 丢失数据文件,没有备份,如何启库的解决方法
- Oracle ASM 详解
- Jforum创建Action
- hdu3374最大最小表示+kmp
- PHP打开zip文件中的图片
- Zookeeper开源客户端框架Curator简介
- 在myEclipse8.5里安装Svn
- Intel特权用户嵌入式帮助在线申请表
- JQuery操作iframe父页面与子页面的元素与方法
- 学习C++是否有价值
- 如何实现Linux下的U盘(USB Mass Storage)驱动