Jetty 6 Embedded for static HTML serving

classic Classic list List threaded Threaded
3 messages Options
dp
Reply | Threaded
Open this post in threaded view
|

Jetty 6 Embedded for static HTML serving

dp
This might have been already answered - pardon my ignorance.  Could someone post a snippet of code for using Jetty 6 in embedded mode to server static HTML pages?
TIA!
Reply | Threaded
Open this post in threaded view
|

Re: Jetty 6 Embedded for static HTML serving

David Yu-2
Hi dp,

Here's a simple alternative to serve static HTML.

        Server server = new Server();
        Connector connector=new SelectChannelConnector();
        connector.setPort(8080);
        server.setConnectors(new Connector[]{connector});
        WebAppContext webappcontext = new WebAppContext();
        webappcontext.setContextPath("/foo");
        webappcontext.setWar("C:/path/to/your/folder");
        server.setHandler(webappcontext);
        server.start();
        server.join();

You can now access your webapp vial localhost:8080/foo. 
If you want the main page to be served at http://localhost:8080/ ...use:
webappcontext.setContextPath("/");
Just put all your static files in one directory and specify the path to that directory using webappcontext.setWar("C:/path/to/your/folder"); The path can be absolute or relative.

Hope this helps,
David


dp wrote:
This might have been already answered - pardon my ignorance.  Could someone
post a snippet of code for using Jetty 6 in embedded mode to server static
HTML pages?
TIA!
  


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Jetty 6 Embedded for static HTML serving

roger
This post has NOT been accepted by the mailing list yet.
Hi David, the below code works great but I have a problem rendering the images that html file uses any advice on how to fix this snippet of my code is the same as the one listed by David. Thanks in advance for your patience in responding to the same.

Thanks
Roger