First, put the jdom-1.0.jar package in the Notes client and Domino Server Java library path :... \ JVM \ Lib \ Ext, and change the notes under the installation path of the server and client respectively. the javauserclasses parameter of ini.
Assume that the proxy name is xmljava, and several parameters are passed in Ajax. Call this proxy. The URL is like/xxx. nsf/xmljava? Openagent & param1 = aaa & param2 = BBB & param3 = CCC. At last, use printwriter to return XML data to the browser for resolution.
Java agent. Java is as follows:
IMPORT java. Io. printwriter;
IMPORT Lotus. Domino. agentbase;
IMPORT Lotus. Domino. agentcontext;
IMPORT Lotus. Domino. Document;
IMPORT Lotus. Domino. Session;
/**
* @ Author Kenny
* NOV 6 and 2009
*/
Public class javaagent extends agentbase {
Public void notesmain (){
Session session = NULL;
Agentcontext = NULL;
Document context = NULL;
Printwriter PW = NULL;
Try {
Session = getsession ();
Agentcontext = session. getagentcontext ();
Context = agentcontext. getdocumentcontext ();
String Param = context. getitemvaluestring ("query_string_decoded ");
// Get the browser parameter, which is the URL? The following section,
// For example, openagent & param1 = aaa & param2 = BBB & param3 = ccc
String [] PS = Param. Split ("\\&|\= ");
// Use specific characters for splitting. & and = are used for splitting to obtain the parameter array. PS [2] = aaa, PS [4] = BBB, PS [6] = ccc
PW = getagentoutput ();
XML = New XML ();
// XML generation method. Be sure to write another class for implementation. Otherwise, JDOM conflicts with the Document Object of Domino !!!
XML. createxml (PW, PS );
PW. Close ();
} Catch (exception e ){
System. Out. println ("javaagent method notesmain () run error:" + E. tostring ());
} Finally {
Try {
If (PW! = NULL) PW. Close ();
If (context! = NULL) Context. Recycle ();
If (agentcontext! = NULL) agentcontext. Recycle ();
If (session! = NULL) Session. Recycle ();
} Catch (exception e ){
System. Out. println ("notesmain () recycle objects error:" + E. tostring ());
}
}
}
}
The XML. Java implementation class for generating XML is as follows:
IMPORT java. Io. printwriter;
IMPORT org. JDOM. Document;
IMPORT org. JDOM. element;
IMPORT org. JDOM. Output. xmloutputter;
/**
* @ Author Kenny
* NOV 6 and 2009
*/
Public class XML {
Public void createxml (printwriter PW, string [] Params ){
Element root = NULL;
Document Doc = NULL;
Try {
Root = new element ("list"); // create a root node
Doc = new document (Root); // create an XML Object
/*
* The data obtained from interaction with the relational database can be put here, which is omitted here
*/
For (INT I = 0; I <Params. length; I ++ ){
// Add a node. Here is only an example. For details about how to generate xml for JDOM, refer to Google
Root. addcontent (new element ("value"). settext (Params [I]);
}
// The following sentence is very important. Make sure that, otherwise, a common string is returned and cannot be parsed into an XML object on the client.
PW. println ("Content-Type: text/XML ");
Xmloutputter xmlout = new xmloutputter ();
Xmlout. Output (Doc, PW );
PW. Close ();
} Catch (exception e ){
System. Out. println ("XML. Java method createxml () run error:" + E. tostring ());
} Finally {
Try {
If (PW! = NULL) PW. Close ();
} Catch (exception e ){
System. Out. println ("createxml () recycle objects error:" + E. tostring ());
}
}
}
}
finally, on the browser side, use javas parser to parse the responsexml object (for specific methods, refer to Google) to get the corresponding data. The preceding Code is successfully tested under Domino r8.5.