Oracle Forms
This article demonstrates how you can
integrate a J2EE application within a Forms application, and establish a
bilateral communication between the two applications.
The provided sample uses 2
special JavaBeans to do the job:
The Enhanced Web
Browser Java bean and the SocketServer
Java Bean
This bean transform the Forms application into a socket server able to receive messages from the outside.
Here is the code used to communicate with the JSP page from forms :
1. The end user chooses a city
via the list item, then makes a call to the JSP in the When-List-Changes trigger:
Declare LC$Url Varchar2(256) ; Begin LC$Url :=
'http://10.75.19.12:8988/Workspace1-socket_client-context-root/go.jsp?city=' || :BL.Search ; Set_Custom_Property('BL.BROWSER1', 1,
'SET_URL', LC$Url); End ; |
2. The JSP page accept one
parameter which name is : city
When the end user clicks on
the html link contained in the JSP page, a call is made to the sendmessage.jsp
page that manages to send a message to the given socket:
href="http://10.75.19.12:8988/Workspace1-socket_client-context-root/sendmessage.jsp?host=localhost&port=4450&msg=<%=sPop%>" |
As you can see, both the
hostname and port number are hard-coded in the JSP page, but you could easily
send these parameters from the Forms module as well as the city name.
Here is the code of the sendmessage.jsp page:
<%@ page import =
"java.io.*" %> <jsp:useBean id="msg"
class="oracle.fd.socket.Client" scope="session" /> <% int iPort = 0 ; String
sHost = "" ; String sMsg
= "" ; if (
request.getParameter("port") != null ) { iPort =
Integer.parseInt(request.getParameter("port")) ; if ( request.getParameter("host") != null
) { sHost
= request.getParameter("host") ; if (
request.getParameter("msg") != null ) {
sMsg = request.getParameter("msg") ;
/* * ok we have hostname, port and message text * so we can send the message */
try{
boolean b = msg.sendMessage(sHost, iPort, sMsg); }
catch (Exception e) {
e.printStackTrace();
throw e;
} } } } %> |
3. Finally, the message is sent
to Forms via the socket in the sendMessage() Java method:
package oracle.fd.socket; import java.io.BufferedReader; import
java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.Socket; public class Client { public
Client() { }
/*
* Send a message to a socket server
*/ public
boolean sendMessage(String host, int port, String sMessage) { Socket
smtpPipe; try {
smtpPipe = new Socket(host, port); if
(smtpPipe == null)
return false; OutputStreamWriter
out = new OutputStreamWriter(smtpPipe.getOutputStream()); if (out
== null)
return false; // send the message
out.write(sMessage + "\r\n");
out.flush();
out.close();
smtpPipe.close(); } catch
(IOException ioe) { return false; } return
true; } } |
4. In the end, the Forms application get the
sent message via the When-Custom-Item-Event trigger.
The samples
provided with this article:
The files provided with this article
contains the following objects:
The 9.0.2 Forms sample : FUSION902.fmb
The Jdeveloper 9i project
that contains the J2EE application : socketclient.zip