Hi:
I am developing a web-based application, which user can interactive with the
Expert via the browser. So I was trying to use servlet which will pass the input
data (from HTML form) to Jess and excute the .clp file. the output will pass to
the servlet and be sent back to browser.
I am using "fetch" and "store" for communicating between jess and java.
The code in servlet is as follows:
//get data from HTML form
String namep="" ;
String valuep="";
Enumeration nameS = req.getParameterNames();
while(nameS.hasMoreElements()) {
namep = (String)nameS.nextElement();
valuep = req.getParameterValues(namep)[0];
}
//excute .clp file,
NullDisplay nd = new NullDisplay();
Rete rete = new Rete(nd);
rete.addUserpackage(new PredFunctions());
try
{ rete.store("A", new Value(namep, RU.STRING));
rete.store("B", new Value(valuep, RU.STRING));
FileInputStream fis = new FileInputStream("test.clp");
Jesp j = new Jesp(fis, rete);
j.parse(false);
//send the Jess PrintStream to browser
toClient.println(nd.stdout());
}
// send error message to browser
catch (ReteException re) {
re.printStackTrace(nd.stderr());
toClient.println("Rete Exception!");
toClient.println(nd.stderr());
}
catch (FileNotFoundException e) {
toClient.println("File not found!");
}
The code of test.clp is:
(defrule startup
=>
(assert ((fetch A) (fetch B)))
(assert (stage yn)))
(defrule 1
?stage <- (stage yn)
?phase <- (phase yes)
=>
(printout t "YES" crlf))
(defrule 2
?stage <- (stage yn)
?phase <- (phase no)
=>
(printout t "NO" crlf))
(reset)
(run)
The running result is that rete exception is send to the browser. It seems that
the test.clp file was not excuted.
Can anybody help!
Thanks!
Beth Zhang
Dept. of Civil Engineering
National University of Singapore
Tel: 65-8746498(o)
Email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------