scalatra_mount

scalatra是如何加入servlet的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
private def mountServlet(
servlet: HttpServlet,
urlPattern: String,
name: String,
loadOnStartup: Int): Unit
= {

val reg = Option(sc.getServletRegistration(name)) getOrElse {
val r = sc.addServlet(name, servlet)
servlet match {
case s: HasMultipartConfig => //如果有HasMultipartConfig 特质
r.setMultipartConfig(s.multipartConfig.toMultipartConfigElement)
case _ =>
}
if (servlet.isInstanceOf[ScalatraAsyncSupport])
r.setAsyncSupported(true)
r.setLoadOnStartup(loadOnStartup)
r
}

reg.addMapping(urlPattern)
}

private def mountServlet(
servletClass: Class[HttpServlet],
urlPattern: String,
name: String,
loadOnStartup: Int): Unit
= {

val reg = Option(sc.getServletRegistration(name)) getOrElse {
val r = sc.addServlet(name, servletClass)
// since we only have a Class[_] here, we can't access the MultipartConfig value
// if (classOf[HasMultipartConfig].isAssignableFrom(servletClass))
if (classOf[ScalatraAsyncSupport].isAssignableFrom(servletClass)) {
r.setAsyncSupported(true)
}
r.setLoadOnStartup(loadOnStartup)
r
}
reg.addMapping(urlPattern)
}
欢迎关注我的公众号:沉迷Spring
显示 Gitment 评论
0%