支援groovlet GSP 的最簡jetty伺服器程式碼
阿新 • • 發佈:2019-01-23
新建lib和www目錄,將groovy-all-1.6.3.jar、jetty-6.1.19.jar、jetty-util-6.1.19.jar、jsp-api-2.1-glassfish-9.1.1.B60.25.p0.jar、servlet-api-2.5-20081211.jar拷貝到lib目錄下,新建SimJettys.groovy程式碼如下,然後執行
set class_path=lib/groovy-all-1.6.3.jar;lib/jetty-6.1.19.jar;lib/jetty-util-6.1.19.jar;lib/jsp-api-2.1-glassfish-9.1.1.B60.25.p0.jar;lib/servlet-api-2.5-20081211.jar
java -cp %class_path% groovy.ui.GroovyMain SimJettys.groovy
set class_path=lib/groovy-all-1.6.3.jar;lib/jetty-6.1.19.jar;lib/jetty-util-6.1.19.jar;lib/jsp-api-2.1-glassfish-9.1.1.B60.25.p0.jar;lib/servlet-api-2.5-20081211.jar
java -cp %class_path% groovy.ui.GroovyMain SimJettys.groovy
import javax.servlet.Servlet
import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.ServletHolder
import org.mortbay.jetty.webapp.WebAppContext
def server = new Server(8080)
def final context = new WebAppContext("www", "/")
context.addServlet(new ServletHolder(new groovy.servlet.TemplateServlet()), "*.gsp")
context.addServlet(new ServletHolder(new groovy.servlet.GroovyServlet()), "*.groovy")
server.setHandler(context)
server.start()