Groovy Quick and Dirty Jetty web server with gsp support (using TemplateServlet)


/ Published in: Groovy
Save to your folder(s)

this example is based on http://groovy.codehaus.org/Grape


Copy this code and paste it in your HTML
  1. // this example is based on http://groovy.codehaus.org/Grape
  2.  
  3. import org.mortbay.jetty.Server
  4. import org.mortbay.jetty.servlet.*
  5. import groovy.servlet.*
  6.  
  7. import org.mortbay.jetty.webapp.WebAppContext;
  8.  
  9. @Grab(group = 'org.mortbay.jetty', module = 'jetty-embedded', version = '6.1.0')
  10. def runServer() {
  11.  
  12. def server = new Server(1234)
  13.  
  14. def context = new Context(server, "/", Context.SESSIONS);
  15.  
  16. context.resourceBase = "."
  17.  
  18. context.addServlet(DefaultServlet, "/")
  19.  
  20. context.addServlet(TemplateServlet, "*.gsp")
  21.  
  22.  
  23. //
  24. /*
  25.   WebAppContext webapp = new WebAppContext();
  26.   webapp.setContextPath("/");
  27.   webapp.setWar("http-server-0.9-SNAPSHOT");
  28.   server.setHandler(webapp);
  29.   */
  30. //
  31.  
  32. server.start()
  33. //sleep duration
  34. println "Press enter or return to stop web server."
  35. System.in.read();
  36. server.stop()
  37. }
  38.  
  39. runServer()

URL: http://groovy.codehaus.org/Grape

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.