通常你会使用一个 Java EE 服务器并实现一个Servlet。
这是一个:
package myservlet
import javax.servlet.http._
class Servlet extends HttpServlet {
/** Servlet's main method. */
protected def welcome (request: HttpServletRequest, response: HttpServletResponse): Unit = {
response.getWriter.write ("hi")
}
override def doGet (request: HttpServletRequest, response: HttpServletResponse): Unit = welcome (request, response)
override def doPost (request: HttpServletRequest, response: HttpServletResponse): Unit = welcome (request, response)
}
然后你会像往常一样在 web.xml 中提到它:
<servlet><servlet-name>MyServlet</servlet-name>
<servlet-class>myservlet.Servlet</servlet-class></servlet>
<servlet-mapping><servlet-name>MyServlet</servlet-name>
<url-pattern>/</url-pattern></servlet-mapping>
有关详细信息,请参阅任何Java Servlet 教程。