From: Timothy J. H. <ti...@cs...> - 2004-09-28 20:16:09
|
On Sep 28, 2004, at 2:12 PM, Geoffrey Knauth wrote: > How do I pass parameters between JScheme servlets? There are several techniques ... As Ken suggests, hidden parameters is a standard one > <input name="abc" type="hidden" value="xyz"> .. Another approach is to use session parameters which are stored on the server and accessible to servlets in the same session. I do this using the following two procedures for storing and accessing session values (which is in the jscheme webapp from CVS in WEB-INF/scheme/servletlib/session.scm > ;; storing session data > (define (session-set request N V) > (.setAttribute (.getSession request) N V)) > > (define (session-get request N Default) > (let ((x (.getAttribute (.getSession request) N))) > (if (equal? x #null) Default x))) This approach is good for passwords where you get them once from the user and the store them in a session attribute. Does this help?? You could probably also "call a servlet" and get its return value by doing a read on a URL... > > (define result > (http-read > > "http://my.company.com:8080/jscheme/my.servlet?a=1&b=2&c=3&d=hi")) > but this can expose you to the danger of infinite servlet loops where servlet A calls servlet B who calls servlet C, etc. The http-read procedure can be defined as follows (but there might be a more elegant solution....) > (define (http-read url-string) > ;; this reads a string from a given url > (define url (java.net.URL. url-string)) > (define http-con (.openConnection url)) > (define buf (java.lang.reflect.Array.newInstance char.class 65536)) > > (define (drain-from-in in) ;; read input lines into a list in > reverse order > (let loop ((n (.read in buf 0 65535)) > (L ())) > (if (equal? n -1) > L > (let ((z (java.lang.String. buf 0 n))) > (loop (.read in buf 0 65535) (cons z L)))))) > > (define (strip-out-header L) ; L is a reversed list of lines from > an http file > (let loop ((L L) (R ())) > (cond ((null? L) R) > ((equal? (first L) "") R) > (else (loop (rest L) (cons (first L) R)))))) > > (define (list->string L) > (let loop ((L L) (z (java.lang.StringBuffer.))) > (if (null? L) > (.toString z) > (loop (rest L) (.append (.append z (first L)) "\n"))))) > > (let ( > (in (java.io.BufferedReader. > (java.io.InputStreamReader. > (.getInputStream http-con))))) > (let* ((result (drain-from-in in))) > (.disconnect http-con) > (list->string (strip-out-header result)) > ))) ---Tim--- > > Geoffrey > -- > Geoffrey S. Knauth | http://knauth.org/gsk > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on > ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give > us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out > more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Jscheme-devel mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-devel |