From: Kenneth Tilton on 22 Jun 2010 20:26 Thomas A. Russ wrote: > "Haris Bogdanovi��" <fbogdanovic(a)xnet.hr> writes: > >> Hi. >> >> I have this piece of code: >> --------------------------------------------------------------------- >> (defun start-page () >> (cl-who:with-html-output-to-string (*standard-output* nil :indent t) >> (:html >> (:body >> (:image :alt "alt" :src "file:///c:/pics/image01.jpg"))))) >> ----------------------------------------------------------------------- >> and when I go to http://localhost:5000, where my hunchentoot is, >> it just renders alternative text "alt" but if copy source code that is >> produced by this: > ... >> Why doesn't it render a picture in the first case ? > > Because we don't have your picture installed on our machines. And a lot > of us aren't running Windows either, so even if we had your picture it > would have a different file path. > > You need to point the image tag at a web-accessible URL and not at your > local file system. We can't just randomly retrieve stuff from your file > system (I'll bet you're glad about that). > Ummm: > So put the picture somewhere that huchentoot will serve it and get to it > with an http: URL instead. Did you want to tell them how? :) On aserve we have publish-file and publish-directory* by which a logical path used in an href gets translated to a physical directory the server knows about, and I recall Hunch does the same albeit with diff syntax. Howsabout we give the OP either a working tag/publish pair, or even better point them to the right place in the Hunch doc. (I can't find it in here: http://www.weitz.de/hunchentoot/ kt * My starter for: http://teamalgebra.com/ Don't let the flets throw ya. (defun serve-soa (&optional (port 8000)) (when *wserver* (shutdown)) (qx-reset) (net.aserve:start :debug nil :port port) (net.aserve::debug-off :all) (flet ((pfl (p f) (publish-file :port port :path p :file f)) (pdr (p d) (publish-directory :port port :prefix p :destination d)) (pfn (p fn) (publish :path p :function fn))) (pdr "/qx/" "/devel/qx/") (pfn "/begin" 'qx-begin) ;; <=== qx-begin (below) gets customized (pfn "/callback" 'qx-callback-js) (pfn "/cbjson" 'qx-callback-json) (let* ((app-root "/devel/socialalgebra/soa") ;; <=== just change this (app-source (format nil "~a/build/" app-root))) (flet ((src-ext (x) (format nil "~a~a" app-source x))) (pfl "/" (src-ext "index.html")) (pdr "/source/" app-source) (pdr "/script/" (src-ext "script/")) (pdr "/resource/" (src-ext "resource/")) (pdr "/jsMath/" "/jsMath-3.6e/") (pfn "/socialalgebra" 'social-algebra) (pfn "/mxedt" 'mx-edt) (pfn "/focusOn" 'session-focus) ;;>>> move this to qxl-session and figure out how to combine )))) With that and qooxdoo I just create an image widget and eventually get back a request for "/resource/my.png" because of how qooxddo works. I am still new to this stuff so I just look for 404 status codes on the missing picture or whatever and then have the monkeys try publishin different paths until the browser is happy. kt -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld
From: Kenneth Tilton on 22 Jun 2010 20:39 Kenneth Tilton wrote: > Thomas A. Russ wrote: >> "Haris Bogdanovi��" <fbogdanovic(a)xnet.hr> writes: >> >>> Hi. >>> >>> I have this piece of code: >>> --------------------------------------------------------------------- >>> (defun start-page () >>> (cl-who:with-html-output-to-string (*standard-output* nil :indent t) >>> (:html >>> (:body >>> (:image :alt "alt" :src "file:///c:/pics/image01.jpg"))))) >>> ----------------------------------------------------------------------- >>> and when I go to http://localhost:5000, where my hunchentoot is, >>> it just renders alternative text "alt" but if copy source code that >>> is produced by this: >> ... >>> Why doesn't it render a picture in the first case ? >> >> Because we don't have your picture installed on our machines. And a lot >> of us aren't running Windows either, so even if we had your picture it >> would have a different file path. >> >> You need to point the image tag at a web-accessible URL and not at your >> local file system. We can't just randomly retrieve stuff from your file >> system (I'll bet you're glad about that). >> > > Ummm: > >> So put the picture somewhere that huchentoot will serve it and get to it >> with an http: URL instead. > > Did you want to tell them how? :) > > On aserve we have publish-file and publish-directory* by which a logical > path used in an href gets translated to a physical directory the server > knows about, and I recall Hunch does the same albeit with diff syntax. > > Howsabout we give the OP either a working tag/publish pair, or even > better point them to the right place in the Hunch doc. (I can't find it > in here: http://www.weitz.de/hunchentoot/ > > kt > > * My starter for: http://teamalgebra.com/ Don't let the flets throw ya. > > (defun serve-soa (&optional (port 8000)) > > (when *wserver* (shutdown)) > (qx-reset) > (net.aserve:start :debug nil :port port) > (net.aserve::debug-off :all) > (flet ((pfl (p f) > (publish-file :port port > :path p > :file f)) > (pdr (p d) > (publish-directory :port port > :prefix p > :destination d)) > > (pfn (p fn) > (publish :path p :function fn))) > > (pdr "/qx/" "/devel/qx/") > (pfn "/begin" 'qx-begin) ;; <=== qx-begin (below) gets customized > (pfn "/callback" 'qx-callback-js) > (pfn "/cbjson" 'qx-callback-json) > > (let* ((app-root "/devel/socialalgebra/soa") ;; <=== just change this > (app-source (format nil "~a/build/" app-root))) > (flet ((src-ext (x) > (format nil "~a~a" app-source x))) > (pfl "/" (src-ext "index.html")) > (pdr "/source/" app-source) > (pdr "/script/" (src-ext "script/")) > (pdr "/resource/" (src-ext "resource/")) > (pdr "/jsMath/" "/jsMath-3.6e/") > (pfn "/socialalgebra" 'social-algebra) > (pfn "/mxedt" 'mx-edt) > (pfn "/focusOn" 'session-focus) ;;>>> move this to qxl-session > and figure out how to combine > )))) > > With that and qooxdoo I just create an image widget and eventually get > back a request for "/resource/my.png" because of how qooxddo works. Here's what I tell qooxdoo: (img "resource/soa/tree-closed.png" :min-width 12 :min-height 12 :scale t :onclick (lambda (self req) (declare (ignorable req)) (setf .instructing t))) Closer to the HTML, it just be an href similar to the string, then you just keep telling Hunch about directories and/or files till it works. kt > > I am still new to this stuff so I just look for 404 status codes on the > missing picture or whatever and then have the monkeys try publishin > different paths until the browser is happy. > > > > kt > -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld
From: Kenneth Tilton on 22 Jun 2010 21:45 Kenneth Tilton wrote: > Kenneth Tilton wrote: >> Thomas A. Russ wrote: >>> "Haris Bogdanovi��" <fbogdanovic(a)xnet.hr> writes: >>> >>>> Hi. >>>> >>>> I have this piece of code: >>>> --------------------------------------------------------------------- >>>> (defun start-page () >>>> (cl-who:with-html-output-to-string (*standard-output* nil :indent t) >>>> (:html >>>> (:body >>>> (:image :alt "alt" :src "file:///c:/pics/image01.jpg"))))) >>>> ----------------------------------------------------------------------- >>>> and when I go to http://localhost:5000, where my hunchentoot is, >>>> it just renders alternative text "alt" but if copy source code that >>>> is produced by this: >>> ... >>>> Why doesn't it render a picture in the first case ? >>> >>> Because we don't have your picture installed on our machines. And a lot >>> of us aren't running Windows either, so even if we had your picture it >>> would have a different file path. >>> >>> You need to point the image tag at a web-accessible URL and not at your >>> local file system. We can't just randomly retrieve stuff from your file >>> system (I'll bet you're glad about that). >>> >> >> Ummm: >> >>> So put the picture somewhere that huchentoot will serve it and get to it >>> with an http: URL instead. >> >> Did you want to tell them how? :) >> >> On aserve we have publish-file and publish-directory* by which a >> logical path used in an href gets translated to a physical directory >> the server knows about, and I recall Hunch does the same albeit with >> diff syntax. >> >> Howsabout we give the OP either a working tag/publish pair, or even >> better point them to the right place in the Hunch doc. (I can't find >> it in here: http://www.weitz.de/hunchentoot/ Is it this?: Fn: create-folder-dispatcher-and-handler Params: uri-prefix base-path &optional content-type => dispatch-fn The Fn name is a bit much, but look at those parameters! Perfect! I now return this thread to those who apparently do not actually know how to help the OP. :) kt >> >> kt >> >> * My starter for: http://teamalgebra.com/ Don't let the flets throw ya. >> >> (defun serve-soa (&optional (port 8000)) >> >> (when *wserver* (shutdown)) >> (qx-reset) >> (net.aserve:start :debug nil :port port) >> (net.aserve::debug-off :all) >> (flet ((pfl (p f) >> (publish-file :port port >> :path p >> :file f)) >> (pdr (p d) >> (publish-directory :port port >> :prefix p >> :destination d)) >> >> (pfn (p fn) >> (publish :path p :function fn))) >> >> (pdr "/qx/" "/devel/qx/") >> (pfn "/begin" 'qx-begin) ;; <=== qx-begin (below) gets customized >> (pfn "/callback" 'qx-callback-js) >> (pfn "/cbjson" 'qx-callback-json) >> >> (let* ((app-root "/devel/socialalgebra/soa") ;; <=== just change this >> (app-source (format nil "~a/build/" app-root))) >> (flet ((src-ext (x) >> (format nil "~a~a" app-source x))) >> (pfl "/" (src-ext "index.html")) >> (pdr "/source/" app-source) >> (pdr "/script/" (src-ext "script/")) >> (pdr "/resource/" (src-ext "resource/")) >> (pdr "/jsMath/" "/jsMath-3.6e/") >> (pfn "/socialalgebra" 'social-algebra) >> (pfn "/mxedt" 'mx-edt) >> (pfn "/focusOn" 'session-focus) ;;>>> move this to qxl-session >> and figure out how to combine >> )))) >> >> With that and qooxdoo I just create an image widget and eventually get >> back a request for "/resource/my.png" because of how qooxddo works. > > Here's what I tell qooxdoo: > > (img "resource/soa/tree-closed.png" > :min-width 12 > :min-height 12 > :scale t > :onclick (lambda (self req) > (declare (ignorable req)) > (setf .instructing t))) > > Closer to the HTML, it just be an href similar to the string, then you > just keep telling Hunch about directories and/or files till it works. > > kt > > > >> >> I am still new to this stuff so I just look for 404 status codes on >> the missing picture or whatever and then have the monkeys try >> publishin different paths until the browser is happy. >> >> >> >> kt >> > > -- http://www.stuckonalgebra.com "The best Algebra tutorial program I have seen... in a class by itself." Macworld
From: vanekl on 23 Jun 2010 01:42 On Jun 22, 6:35 pm, "Haris Bogdanovi " <fbogdano...(a)xnet.hr> wrote: > I put img instead of image and put the image in lispworks working dir > and tried relative pathname to the image but no success. > I guess hunchentoot has it's own current working dir > so I should put my picture in that directory. > How do I find out or set that directory ? Hunchentoot does not automatically serve files based on where you place them in your file system. You have to tell hunchentoot which files are acceptable to serve, and exactly how to serve them. For example, this is what I use to tell hunchentoot how to serve image files: (defun serve-image () (let ((default-mime-type "image/jpeg") (default-path (url-to-local-dir (tbnl:request-uri*)))) ;; adding an expiration date saves about .1 seconds response time ;; (the image doesn't have to be resent each time) (set-expiration) (let ((path (make-pathname :name (file-name-no-ext (tbnl:script-name*)) :type (file-extension (tbnl:script-name*)) :version nil :defaults default-path))) (setf (tbnl:content-type*) (or (hunchentoot:mime-type path) default-mime-type)) (with-open-file (in path :element-type 'flex:octet) (let ((image-data (make-array (file-length in) :element-type 'flex:octet))) (read-sequence image-data in) image-data))))) You could also look in the hunchentoot/test directory on your computer and search on "jpg" to see how Edi has done it. You don't have all the sub-functions that I show in 'serve-image,' but they are easy to write once you have a basic understanding of how an http server works. This is how I tell hunchentoot that it's OK to serve images only from this one "img" directory: (setf (gethandler 'img) (make-instance 'handler :url "^/img/.*" :name 'img :handler 'serve-image)) I set my handlers up a little differently than you do, so this code wont work on your system, but you should understand that a request handler of some sort is necessary not just for HTML but for each type of HTTP request. If you want to know more about how hunchentoot serves files, place trace calls in your handlers and your main dispatch function (assuming you wrote one). (tbnl:log-message :info "This handler is being invoked now!") If you want to see how the most important hunchentoot variables are set, review and run hunchentoot test function / handler "info": (defun info () (with-html (:html (:head (:title "Hunchentoot Information")) (:body (:h2 (hunchentoot-link) " Information Page") (:p "This page has been called " (:b (fmt "~[~;once~;twice~:;~:*~R times~]" (incf count))) " since its handler was compiled.") (info-table (host) (acceptor-address *acceptor*) (acceptor-port *acceptor*) (remote-addr*) (remote-port*) (real-remote-addr) (request-method*) (script-name*) (query-string*) (get-parameters*) (headers-in*) (cookies-in*) (user-agent) (referer) (request-uri*) (server-protocol*))))))) Finally, there is a hunchentoot mailing list that is a more appropriate venue for this question and other hunchentoot questions. The mailing list is not hard to find if you have internet access, and you will probably get more accurate and timely answers there assuming you do your part and show some initiative by doing legwork before asking the question. One of those steps would be reviewing sample code that comes with hunchentoot. It's in the hunchentoot test directory on your computer.
From: Captain Obvious on 23 Jun 2010 05:38 HB> I put img instead of image and put the image in lispworks working dir HB> and tried relative pathname to the image but no success. HB> I guess hunchentoot has it's own current working dir HB> so I should put my picture in that directory. HB> How do I find out or set that directory ? You do not have a good understanding how web servers work. They do not operate "in a working directory", they serve requests. It is your duty to configure it to do what you want it to do. Files like image01.jpg are usually called "static files" in context of web serving. So you have those static files in some directory. Now you need to configure Hunchentoot to serve those files, e.g. on request http://localhost:5000/pics/image01.jpg it should respond with that image from a certain directory on your disk. Hunchentoot has a number of functions which can assist you in serving static files. Perhaps easiest to use one: create-folder-dispatcher-and-handler uri-prefix base-path &optional content-type => dispatch-fn If you call it like (create-folder-dispatcher-and-handler "/pics" "c:/mypics/") it will return a dispatcher. Then you need to add this dispatcher into a global dispatch table. E.g. (setf *dispatch-table* (list ;; your stuff goes here. (create-folder-dispatcher-and-handler "/pics" "c:/mypics/") 'hunchentoot:dispatch-easy-handlers 'hunchentoot:default-dispatcher)) The way how dispatching works is described here: http://www.weitz.de/hunchentoot/#request-dispatch Basic idea is that it goes through all dispatchers in *dispatch-table* and calls them to check whether they can handle request.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Google Adsense Account Approval With In 4 Hours Next: cl-weblocks |