上篇博客《OFbiz--简单介绍》我们介绍了OFbiz是什么,以下我们就開始用OFbiz开发我们的第一个程序--HelloWorld。

过程例如以下:

首先在hot-deploy下新建文件夹simple。文件夹结构例如以下:

1.ofbiz-component.xml文件配置

此文件为程序的启动配置。配置webapp的名称、位置、权限、信息。

<?

xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="simple" 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="simple"
title="Simple"
server="default-server"
base-permission="OFBTOOLS"
location="webapp/simple"
mount-point="/simple"
app-bar-display="false"/> </ofbiz-component>

2.web.xml文件配置

配置默认的实体载入器、分发器、装饰器。能够与springMVC或struts的项目中的web.xml进行比較。会发现有些地方是同样的。做为MVC模式的项目,在配置文件里都须要配置ControlServlet进行请求分法。

<?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>
<!-- 有关实体引擎 -->
<context-param>
<param-name>entityDelegatorName</param-name>
<param-value>default</param-value>
</context-param> <!-- 有关服务引擎 -->
<context-param>
<param-name>localDispatcherName</param-name>
<param-value>school</param-value>
</context-param> <!-- 有关界面装饰器 -->
<context-param>
<param-name>mainDecoratorLocation</param-name>
<param-value>component://simple/widget/SimpleScreens.xml</param-value>
</context-param> <!-- 配置訪问过滤器 -->
<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>/error:/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/main</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>
<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过期时间 -->
<session-config>
<session-timeout>60</session-timeout>
</session-config> <!-- 配置默认界面 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

3.controller.xml

配置request请求及请求的视图。

<?

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">
<include location="component://common/webcommon/WEB-INF/common-controller.xml"/>
<!-- Request Mappings -->
<request-map uri="main">
<security https="false" auth="false"/>
<response name="success" type="view" value="main"/>
</request-map>
<!-- View Mappings -->
<view-map name="main" type="screen" page="component://simple/widget/SimpleScreens.xml#main"/> </site-conf>

4.SimpleScreens.xml

配置界面信息,一个screen是一个定义的界面。

<?

xml version="1.0" encoding="UTF-8"?>
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-screen.xsd">
<screen name="main">
<section>
<widgets>
<label text="Hello World"/>
</widgets>
</section>
</screen>
</screens>

5.訪问

訪问地址:http://localhost:8080/simple/control/main

结果例如以下:

总结

通过如上操作,我们建立了自己的第一个OFbiz程序,这个程序不涉及实体的CRUD、不涉及请求的重定向、不涉及表单拼装界面、不涉及请求服务。以下我们会一点点的完好这个Demo.

大家能够感受到使用OFbiz如此简单,没有一行java代码。全是xml配置文件。大家仅仅要熟悉xml的编写规范就可以高速上手。

OFbiz--HelloWorld的更多相关文章

  1. OFBiz进阶之HelloWorld(五)创建新实体

    参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...

  2. OFBiz进阶之HelloWorld(三)CRUD操作

    参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...

  3. OFBiz进阶之HelloWorld(二)创建热部署模块

    参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...

  4. OFBiz进阶之HelloWorld(一)创建热部署模块

    创建热部署模块 参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Developm ...

  5. ofbiz初级教程

    本教程是ofbiz 基本应用,它涵盖了OFBiz应用程序开发过程的基本原理.目标是使开发人员熟悉最佳实践,编码惯例,基本控制流程以及开发人员对OFBiz定制所需的所有其他方面. 本教程将帮助您在OFB ...

  6. 使用webstorm+webpack构建简单入门级“HelloWorld”的应用&&引用jquery来实现alert

    使用webstorm+webpack构建简单入门级"HelloWorld"的应用&&构建使用jquery来实现 1.首先你自己把webstorm安装完成. 请参考这 ...

  7. Idea下用SBT搭建Spark Helloworld

    没用过IDEA工具,听说跟Eclipse差不多,sbt在Idea其实就等于maven在Eclipse.Spark运行在JVM中,所以要在Idea下运行spark,就先要安装JDK 1.8+ 然后加入S ...

  8. 菜鸟学Struts2——HelloWorld

    写在前面 自从工作后就过上了只有一个月记忆的生活,太健忘,很多学过的东西因为用得少便忘记了,第二次学习struts,为了以后便于查阅,开始自己的博客之旅.Struts的学习还是从Hello World ...

  9. 初识AngularJS 之 HelloWorld和数据绑定

    1.Hello World 我用的开发工具是   atom   ,大家有需要的话可以找我要安装包嘻嘻 第一步: 写入以下代码: <!DOCTYPE html> <html ng-ap ...

  10. java环境搭建和写出一个Helloworld

    一.安装环境和配置环境变量(必要环节) 安装java并配置环境变量 :在"系统变量"中设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击 ...

随机推荐

  1. leetcode Longest Palindromic Substring python

    class Solution(object): def longestPalindrome(self, s): """ :type s: str :rtype: str ...

  2. day5_python学习笔记_chapter6_字符串列表元组

    1. 序列:seq[n], seq[x:y], seq * n序列重复n次,切片, 序列翻转 s=”abcde", s[::-1]="edcba" 内建函数:1. 类型转 ...

  3. SQL2-子查询、join查询

    SQL常用高级查询包括:Join查询.子查询. 子查询: USE flowershopdb --子查询:在一个select语句使用另一个select 语句作为条件或数据来源. --查询块:一个sele ...

  4. Web颜色搭配 - 收集

    颜色1  颜色一   背景 字 RGB 43,41,46 92,187,207 HEX #2B292E #5CBBCF HSB 264,11,18 190,56,81 CMYK 7,11,0,82 5 ...

  5. python基础学习笔记4--抽象

    抽象 1.函数: 1) 函数是可以调用,它执行某种行为并且返回一个值.可以通过callable函数来判断函数是否可调用. eg:>>> def hello(name):        ...

  6. 求1~n直接1出现的次数

    参考前人的统计思想:分别统计个.十.百...亿等第N位上1出现的次数. 如ABCDE,在统计D位1出现的次数时,用D做分割符,ABC为Before,E为After. 分情况考虑:(n为D的length ...

  7. Qt项目管理(33个规则)

    2016-06-20 花莫弦 小小杂货铺LY 一.qmake的介绍 qmake是Trolltech公司创建的用来为不同的平台和编译器书写Makefile的工具. 手写Makefile是比较困难并且容易 ...

  8. android数据库持久化框架

    android数据库持久化框架

  9. HDU 5800 To My Girlfriend(单调DP)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5800 [题目大意] 给出一个容量上限s,f[i][j][k][l][m]表示k和l两个物品不能选,i ...

  10. Advanced Customization of the jQuery Mobile Buttons | Appcropolis

    Advanced Customization of the jQuery Mobile Buttons | Appcropolis Advanced Customization of the jQue ...