提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|其它|编辑:郝浩|2009-09-03 10:49:31.000|阅读 637 次
概述:本文描述了通过使用 Servlet 和 JavaServer Pages来集成瘦客户机与 MQSeries。这种集成需要用户详细填写 HTML 表单,并从该表单中收集用户数据然后通过一个消息队列将数据发送到后端应用程序。接下来后端应用程序将处理该表单数据并通过该消息队列发回一个应答。该应答需要在浏览器中显示。
#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>
本文描述了通过使用 Servlet 和 JavaServer Pages来集成瘦客户机与 MQSeries。这种集成需要用户详细填写 HTML 表单,并从该表单中收集用户数据然后通过一个消息队列将数据发送到后端应用程序。接下来后端应用程序将处理该表单数据并通过该消息队列发回一个应答。该应答需要在浏览器中显示。
体系结构概述 下图给出了所建议的解决方案体系结构。它涉及三层方法。

处理流程
用户填写 HTML 表单。 将表单发送给 servlet。 servlet 将该 HTTP 请求转换成一个 MQSeries 消息,并将其放入一个队列。 后端应用程序处理该消息,然后通过消息队列发回一个应答。 servlet 从队列中检索消息,并将其存放在一个 Java Bean 中。 然后 servlet 调用编译过的 JavaServer Page 并动态生成结果 HTML 页面。 JSP 从 Java Bean 检索该页面的消息内容,将其合并到 HTML,然后将结果页面回显在浏览器上。
该解决方案利用了下列技术:
HTML/HTTP、Java - servlet、Java Beans 和 JavaServer Page、Web 服务器、消息队列
该解决方案集成了下列产品:
Netscape 4.0/Internet Explorer 3.0 或更高版本 、IBM HTTP Server 3.0 、WebSphere 2.02 、JDK 版本 1.1.7 、MQSeries 版本 5.0
连接至 MQSeries
我们选择 servlet 模型是因为该模型相对于 CGI 有许多优点。servlet 是扩展了 Web 服务器的功能的标准服务器端 Java 应用程序。servlet 完全运行在 Web Server 上,不会将任何东西下载到浏览器。在装入期间或初始请求期间会将 servlet 装入服务器的地址空间。在初始请求之后,servlet 非常迅速地作出响应。servlet 的 init 方法为 servlet 的运行做好了准备。每个 servlet 装入只调用一次 init 方法。在 init 方法中,按如下建立到 MQSeries 队列管理器的连接:
public void init(ServletConfig config)
throws ServletException {
super.init(config);
try {
//Create a connection to the queue manager
qMgr = new MQQueueManager("NC.QManager");
}
catch (MQException ex)
{
System.out.println
("An MQ error occurred in init(): Completion code "
+ ex.completionCode +
" Reason code" + ex.reasonCode);
try
{
if (qMgr != null)
//Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException e)
{
System.out.println("An MQ error occurred "
+ "in init() while disconnecting:" + " Completion code " +
e.completionCode + " Reason code" + e.reasonCode);
}
}
}
由于只须建立一次到 MQSeries 的队列管理器的连接,并且建立连接需要很长时间,因此 init 方法是执行这一过程的理想位置。然后对该 servlet 的后继调用会执行得更快。WebSphere 也允许用户通过使用管理 GUI 预先装入 servlet,因此随着队列管理器连接的建立,servlet 做好了准备,接下来就等着传递任何消息。
如果在 init 方法中捕获到 MQException,则上述代码会与队列管理器断开连接。结果是,为了建立与队列管理器的连接,用户将不得不重新装入 servlet。
为了使 servlet 与 MQSeries 对话,必须使用 MQSeries Bindings for Java。MQSeries Bindings for Java 使您能够用 Java 语言编写 MQSeries 应用程序。这些应用程序直接与 MQSeries 队列管理器通信以提供高生产率、高性能开发选项。它们使用 Java 本机方法直接调用到现有的队列管理器 API 而不是通过 MQSeries 服务器连接通道进行通信;这为 Java MQSeries 应用程序提供了更佳性能。在代码中我们必须导入“com.ibm.mqbind.*”包。MQSeries 的 java 类也应该位于 WebSphere 的类路径中;这将允许 WebSphere 应用程序服务器定位 MQSeries Bindings for Java 包。
创建 MQ 消息
由于 BillingAddressServlet 主要用于处理来自 AddressInputForm 的 HTTP 请求,我们对 HttpServlet 生成子类。 GenericServlet 的这个抽象子类实现了用于处理请求的缺省 service() 方法。覆盖的最常见方法包括 doGet() 和 doPost()。下面的示例将覆盖 doPost() 方法。AddressInputForm 通过下面的调用来调用这个 doPost() 方法:
<FORM METHOD=POST ACTION="/servlet/BillingAddressServlet">
POST 请求发送一个 HTTP 消息主体,该消息主体含有发给 servlet 的所有数据。然后 doPost() 方法从输入中创建下列消息字符串:
String tempAddress = "Input information is";
res.setContentType("text/plain");
..............
if ("application/x-www-form-urlencoded".equals(req.getContentType()))
{
System.out.println("In doPost()");
Enumeration enum = req.getParameterNames();
while (enum.hasMoreElements())
{
String name = (String) enum.nextElement();
String values = req.getParameter(name);
if(values != null) {
tempAddress = tempAddress + "; " + name + ": " + values;
}
}
发送消息
然后通过使用下列代码调用 putOrder() 方法,doPost() 方法将消息字符串放入消息队列:
public void
putOrder(String tempAddress) {
try {
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
//Specify the queue that we wish to open, and the open options.
MQQueue ncOrderDataQ = qMgr.AccessQueue("NC.OrderCreateQ",
openOptions,
qManager,
null, // no dynamic q name
null); // no alternate user id
//Define a MQ message
MQMessage customerAddress = new MQMessage();
customerAddress.writeUTF(tempAddress);
//specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
//put the message on the queue
ncOrderDataQ.put(customerAddress, pmo);
//Close the queue
ncOrderDataQ.close();
}
catch .........
检索消息
要检索由后端应用程序返回的消息,doPost() 方法调用 orderUpdateStatus() 方法。orderUpdateStatus() 方法使用下列代码检索队列中的消息:
public String orderUpdateStatus() {
String msgText = null;
try {
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
//Specify the queue that we wish to open, and the open options.
MQQueue ncOrderUpdateQ = qMgr.AccessQueue("NC.UpdateQ",
openOptions,
qManager,
null, // no dynamic q name
null); // no alternate user id
//create a new get the message
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.messageId = MQC.MQMI_NONE;
//set the get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();
//get the message off the queue
ncOrderUpdateQ.get(retrievedMessage, gmo);
//Display the message
msgText =
retrievedMessage.readString(retrievedMessage.getMessageLength()); //for NC.UpdateQ
//Close the queue
ncOrderUpdateQ.close();
}
catch .........
调用 JSP
最后,putOrder() 方法调用 performTask() 方法,以将消息存储在 BillingAddress Bean 中。然后 Servlet 调用 AddressOutputPage JSP,并将 BillingAddressBean 的句柄传给它。JSP 抽取出动态内容(即,来自 Java Bean 的消息)并将它们合并进显示在浏览器上的 HTML 页面中。
public void performTask(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String returnMessage) {
try
{
// instantiate the bean
BillingAddressBean myBillingAddressBean = new BillingAddressBean();
// set the return message in the bean
myBillingAddressBean.setMQReturnMessage(returnMessage);
// store the bean in the request so it can be accessed by
pages which are accessed with callPage()
((com.sun.server.http.HttpServiceRequest)request).setAttribute
("BillingAddressBean", myBillingAddressBean);
// Call the output page
((com.sun.server.http.HttpServiceResponse)response).callPage
("/AddressOutput
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
文章转载自:IT专家网



接DevExpress原厂商通知,将于近日上调旗下产品授权价格,现在下单客户可享受优惠报价!
面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营