Failed to get message in LISP hunchentoot

I am trying to implement a simple Hunchentoot based email example.

Here is the code:

(define-easy-handler (test :uri "/test") () 
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html 
     (:body
      (:h1 "Test")
      (:form :action "/test2" :method "post" :id "addform"
     (:input :type "text" :name "name" :class "txt")
     (:input :type "submit" :class "btn" :value "Submit"))))))

(define-easy-handler (test2 :uri "/test2") (name)
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html 
     (:body
      (:h1 name)))))

I can correctly connect to http://127.0.0.1:8080/test and see the text input form. But when I send the text, I get a blank page where I was expecting a page with the title specified in the text input.

Not sure if it’s wrong, can anyone consult?

+4
source share
1 answer

Change your handler to

(define-easy-handler (test2 :uri "/test2") (name)
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html 
     (:body
     (:h1 (str name))))))

Then it should work. Read the cl-who documentation. Especially information about local macros. Here I include the relevant documentation.

, , , , , ​​ :

  • , ( ),

    (let ((result form)) (when result (princ result s)))
    
    (loop for i below 10 do (str i)) =>
    (loop for i below 10 do
      (let ((#:result i))
        (when #:result (princ #:result *standard-output*))))
    
  • , (fmt form *),

    (format s form*)
    
    (loop for i below 10 do (fmt "~R" i)) => (loop for i below 10 do (format s "~R" i))
    
  • , ( esc),

    (let ((result form)) (when result (write-string (escape-string result s))))
    
  • (htm form *), , , .. WITH-HTML-OUTPUT.

    (loop for i below 100 do (htm (:b "foo") :br))
    => (loop for i below 100 do (progn (write-string "<b>foo</b><br />" s)))
    
+5

All Articles