上篇博客《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. html object元素

    知道object是播放音频,但是想了解具体点,百度一下,感觉模模糊糊的,感觉看不大明白,最后找到一个解释比较详细,先从应用,到解释具体属性, 具体网址是: http://www.w3school.co ...

  2. PCB流程-外型加工

  3. VC++中的类的内存分布(上)(通过强制转换,观察地址,以及地址里的值来判断)

    0.序 目前正在学习C++中,对于C++的类及其类的实现原理也挺感兴趣.于是打算通过观察类在内存中的分布更好地理解类的实现.因为其实类的分布是由编译器决定的,而本次试验使用的编译器为VS2015 RC ...

  4. 美国vps哪个比较好,vps国内访问速度最快!

    沃网中国是一家成立于2008年的国内idc商,提供基于hyper-v架构的VPS产品,数据中心包括国内电信.美国洛杉矶等,他们采用的是国内访问最快的加州机房ping值,160-180左右相当给力的速度 ...

  5. SBT模版

    /*Author:WNJXYK*/ #include<cstdio> using namespace std; ; struct SBT{ int left; int right; int ...

  6. Is it possible to implement a Firebug-like “inspect element” DOM element highlighter with client-side JavaScript?

    Is it possible to implement a Firebug-like "inspect element" DOM element highlighter with ...

  7. andrewchilds/jQuery.DomOutline

    andrewchilds/jQuery.DomOutline DOM - 使用Javascript:让用户选择一个类似Firebug的HTML元素? -

  8. JAVA訪问URL

    JAVA訪问URL: package Test; import java.io.BufferedReader; import java.io.IOException; import java.io.I ...

  9. 阿里云Ubuntu部署java web(2) - 配置tomcat

    系统版本号:Ubuntu12.04 64位 安装: 首先要安装java(測试时使用的版本号是6b27-1.12.6-1ubuntu0.12.04.2).版本号可自行选择,但不同版本号配置方法可能不同. ...

  10. CreateFileMapping使用方法

    CreateFileMapping的MSDN翻译和使用心得   測试创建和打开文件映射的时候老是得到"句柄无效"的错误, 细致看了MSDN以后才发觉是函数认识不透, 这里把相关的解 ...