<div dir="ltr">The behavior is correct. It's just not the behavior you want. <div><br></div><div>When you start up the web server, the default URL for the page is:<div><br></div><div><a href="http://localhost:8000/servlets/standalone.rkt">http://localhost:8000/servlets/standalone.rkt</a><br>
</div><div><br></div><div>So "/puppy.jpg" really means this:</div><div><br></div><div><a href="http://localhost:8000/puppy.jpg">http://localhost:8000/puppy.jpg</a><br></div><div><br></div><div>Which works, because puppy.jpg is in server-root-path. Whereas the relative URL "puppy.jpg" means this:</div>
<div><br></div><div><a href="http://localhost:8000/servlets/puppy.jpg">http://localhost:8000/servlets/puppy.jpg</a><br></div><div><br></div><div>And indeed, you get no puppy, because the server is looking in the subdirectory "servlets", which doesn't exist in your server-root-path.</div>
<div><br></div><div>Thus you have two choices: </div><div><br></div><div>1) Add the #:servlet-path parameter, which lets you attach the servlet to a URL at the top level, like so:</div><div><br></div><div><div>(serve/servlet </div>
<div> start</div><div> #:server-root-path SOMEPATH</div><div> #:servlet-path "/standalone.rkt"</div><div> )</div></div><div><br></div><div>Now when you start the web server, the URL for the page will be:</div><div>
<br></div><div><a href="http://localhost:8000/standalone.rkt">http://localhost:8000/standalone.rkt</a><br></div><div><br></div><div>And when you link to "puppy.jpg" (no forward slash), it will mean:</div><div><br>
</div><div><a href="http://localhost:8000/puppy.jpg">http://localhost:8000/puppy.jpg</a><br></div><div><br></div><div>And you will get a puppy. (Of course, "/puppy.jpg" will still work.)</div><div><br></div><div>
2) Keep your existing server configuration and instead put a "servlets" subdirectory within D:/Tobias/server-root/htdocs/, and puppy.jpg within it. Then you can use "puppy.jpg" as a relative URL.</div>
<div><br></div><div>The docs for serve/servlet cover servlet-path [1], though your question is fair because this consequence is a little unexpected. I don't know the policy reason for having the default servlet-path be "/servlets/standalone.rkt" rather than something at the top level, like "/standalone.rkt".</div>
<div><br></div><div>[1] <a href="http://docs.racket-lang.org/web-server/run.html?q=serve/servlet">http://docs.racket-lang.org/web-server/run.html?q=serve/servlet</a></div><div><br></div></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Jan 28, 2014 at 1:38 PM, Janos Tobias Locsei <span dir="ltr"><<a href="mailto:jtlocsei@cantab.net" target="_blank">jtlocsei@cantab.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Hi Matthew,<br></div><div><br>Here's an example without using templates, but the same sort of behavior applies when using templates too.<br><br><span style="font-family:courier new,monospace">#lang racket<br>
<br>(require web-server/servlet<br> web-server/servlet-env)<br><br>(define SOMEPATH<br> (build-path "D:\\Tobias\\server-root"))<br><br>(define (start request)<br> (response/xexpr<br> `(html (head (title "Hello world"))<br>
(body (h1 "Hello world")<br> (img ([src "/puppy.jpg"] [alt "cute puppy"]))))))<br>; puppy.jpg is located at D:/Tobias/server-root/htdocs/puppy.jpg <br>; Image only displays if I use the leading forward slash like this<br>
<br>(serve/servlet <br> start<br> #:server-root-path SOMEPATH<br> )</span><br><br></div>I noticed that the leading forward slash is used in the web applications tutorial of the racket documentation, e.g. when referencing a css file (search page for "<span>test-static.css"):<br>
</span><span></span><a href="http://docs.racket-lang.org/continue/" target="_blank">http://docs.racket-lang.org/continue/</a><span class="HOEnZb"><font color="#888888"><br><span></span><div><br></div><div>Tobias<br></div>
<div><br><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On 28 January 2014 19:27, Matthew Butterick <span dir="ltr"><<a href="mailto:mb@mbtype.com" target="_blank">mb@mbtype.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I've not experienced this issue with the Racket web server. When you append a leading forward slash to a URL, you're obviously telling the browser something completely different about where to find the file. I would suspect it has something to do with either file organization, Racket web server configuration, or both. <div>
<br></div><div>Where are myimage.jpg and mytemplate.html in relation to one another? In the same directory? </div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, Jan 28, 2014 at 7:04 AM, Janos Tobias Locsei <span dir="ltr"><<a href="mailto:jtlocsei@cantab.net" target="_blank">jtlocsei@cantab.net</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div><div><div><div>I noticed that when using the racket web server one needs to include a leading forward slash when referencing static files e.g. a style.css or an image.jpg. Is there a rationale for this? It's different than the usual html convention, and it means that when using html template files it's not possible to preview the template in the web browser without running the web server. <br>
<br></div>For example, I have a file mytemplate.html that includes the line<br><br></div><img src="/myimage.jpg" /><br><br></div>The leading "/" is required for the image to be found by the racket web server but it means that I can't preview mytemplate.html in my web browser without first firing up the racket web server. <br>
<br>It's not a big deal but I'm just wondering if there's a way around this.<span><font color="#888888"><br><br></font></span></div><span><font color="#888888">Tobias<br><br><br>
<div><div><div><div><div><br><br></div></div></div></div></div></font></span></div>
<br></div></div>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>