本篇文章主要介绍简单例子,OFBIZ的其他介绍就先不说了,放在后面的博文中。
1、目录结构
说明:在hot-deploy目录下建立文件夹learning,为例。注意先把文件扔到hot-deploy目录下再启动服务器。
2、创建ofbiz-component.xml文件
a.作用:创建此文件,负责让OFBIZ知道learning组件的信息,可以参考applications/accounting/ofbiz-component.xml。
b.内容如下:
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?> <ofbiz-component name="learning" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd"> <resource-loader name="main" type="component"/> <webapp name="learning" title="Learning" server="default-server" base-permission="OFBTOOLS" location="webapp/learning" mount-point="/learning" app-bar-display="false"/> </ofbiz-component> </span>
说明:第一个节点中name=”learning”,指的是组件名,告诉OFBIZ加载我们自己定义的name组件,这个名字必须唯一,不能与OFBIZ其他组件名相同。
Webapp节点:
name: 定义web应用的名字
title: 这个是应用的标识,显示在应用工具条中的名字
server: 让ofbiz知道是哪个server
location:learning组件指向的webapp的路径,这里用的是相对路径
mount-point:应用的访问路径
app-bar-display:应用的title是否要显示
3、创建web.xml
a.路径:${learning/webapp/learning}/WEB-INF
b.内容:(基本每个web.xml都是一样的,从applications里面拷贝一个过来即可)
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>learning</display-name> <description>The First Hello World Application</description> <context-param> <param-name>entityDelegatorName</param-name> <param-value>default</param-value> </context-param> <!-- 本地调用名 start 刘腾腾 --> <context-param> <param-name>localDispatcherName</param-name> <param-value>learning</param-value> </context-param> <!-- 本地调用名 end 刘腾腾 --> <!-- 主修饰器位置,值应该与ofbiz-component.xml里的mount-point相匹配 start 刘腾腾 --> <context-param> <param-name>mainDecoratorLocation</param-name> <param-value>component://simple/widget/CommonScreen.xml</param-value> <description>The location of the main-decorator screen to use for this webapplreferred to as a context variable in screen def XML files.</description> </context-param> <!-- 主修饰器位置,值应该与ofbiz-component.xml里的mount-point相匹配 end 刘腾腾 --> <filter> <filter-name>ContextFilter</filter-name> <display-name>ContextFilter</display-name> <filter-class>org.ofbiz.webapp.control.ContextFilter</filter-class> <init-param> <param-name>disableContextSecurity</param-name> <param-value>N</param-value> </init-param> <init-param> <param-name>allowedPaths</param-name> <param-value>/control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/includes/maincss.css</param-value> </init-param> <init-param> <param-name>errorCode</param-name> <param-value>403</param-value> </init-param> <init-param> <param-name>redirectPath</param-name> <param-value>/control/learning</param-value> </init-param> </filter> <filter-mapping> <filter-name>ContextFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class> </listener> <listener> <listener-class>org.ofbiz.webapp.control.LoginEventListener</listener-class> </listener> <servlet> <servlet-name>ControlServlet</servlet-name> <display-name>ControlServlet</display-name> <description>Main Control Servlet</description> <servlet-class>org.ofbiz.webapp.control.ControlServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ControlServlet</servlet-name> <url-pattern>/control/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> </span>
4、创建controller.xml
a.作用:让OFBIZ根据不同的请求去做相应的事。
b.内容
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?> <site-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/site-conf.xsd"> <!-- 引入OFBIZ的公共控制配置 ltt --> <include location="component://common/webcommon/WEB-INF/common-controller.xml"/> <description>Practice Component Site Configuration File</description> <owner>Copyright 2001-2009 The Apache Software Foundation</owner> <!-- OFBIZ调用该class处理screen中的xml --> <handler name="screen" type="view" class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/> <!-- Request Mappings --> <request-map uri="main"> <security https="false" auth="false"/> <response name="success" type="view" value="main"/> </request-map> <!-- end of request mappings --> <!-- View Mappings --> <view-map name="main" type="screen" page="component://simple/widget/SimpleScreens.xml#main"/> <!-- change the path to the following if the above doesn't work for you --> <!-- end of view mappings --> </site-conf> </span>
5、简单页面
a. 路径:${learning/widget}
b. 建LearningScreen.xml
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?> <Screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-screen.xsd"> <screen name="main"> <section> <widgets> <label text="===========liutengteng=======is a good girl!========"/> </widgets> </section> </screen> </Screens></span>
6、运行结果
a.地址 http://localhost:8080/learning/control/main
b. 效果
7、总结
这是一个简单的OFBIZ的入门小例子,通过一些配置文件,就将我们的系统搭起来了,很快捷,项目的加载部署也很快,灵活配置。下面博文将持续介绍OFBIZ。
时间: 2024-10-08 06:41:27