Discussion:
empty web page
a
2010-05-31 11:16:04 UTC
Permalink
Hi.

When I try to open a web page generated by cl-who I get an empty web page:

------------------------------------------------------------
(start (make-instance 'acceptor :port 8000))

(push (create-prefix-dispatcher "/index.html" 'index) *dispatch-table*)

(defun index ()
(with-html-output (*standard-output* nil :indent t)
(:html
(:head
(:title "Test page"))
(:body
(dotimes (x 10)
(:htm
(:p "Text"))))))
-----------------------------------------------------------

and page on http://localhost:8000/index.html is empty.
The source of the page is just:
----------------
</body>
</html>
--------------

Where is the problem ?
If I remove dynamic code "(dotimes (x 10) ..."
then it renders the page correctly.

Thanks
Edi Weitz
2010-05-31 11:45:02 UTC
Permalink
A standard Hunchentoot handler must return its output as a string and
not send it to *standard-output*.

Edi.
Post by a
Hi.
------------------------------------------------------------
(start (make-instance 'acceptor :port 8000))
(push (create-prefix-dispatcher "/index.html" 'index) *dispatch-table*)
(defun index ()
  (with-html-output (*standard-output* nil :indent t)
    (:html
     (:head
      (:title "Test page"))
     (:body
      (dotimes (x 10)
        (:htm
         (:p "Text"))))))
-----------------------------------------------------------
and page on http://localhost:8000/index.html is empty.
----------------
  </body>
</html>
--------------
Where is the problem ?
If I remove dynamic code "(dotimes (x 10) ..."
then it renders the page correctly.
Thanks
_______________________________________________
cl-who-devel site list
http://common-lisp.net/mailman/listinfo/cl-who-devel
Sebastian Tennant
2010-06-04 09:19:47 UTC
Permalink
A standard Hunchentoot handler must return its output as a string and not
send it to *standard-output*.
This should make things a little clearer:

;;; define *http-stream* as a special variable
;;; (so that it can be used anywhere, not just in function 'index')
(defvar *http-stream* nil)

(defun reapeat-para (stream body n)
(with-html-output (stream)
(dotimes (i n)
(:htm
(:p (str body))))))

(defun index ()
(with-html-output-to-string (*http-stream* nil :indent t)
(:html
(:head
(:title "The first dissenter"))
(:body
(repeat-para *http-stream* "Romans go home" 100)))))


Untested, but it should help.

Seb
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap
Loading...