6

I want to call another internal url from my scalatra 'controller'. I can't do a simple redirect, as there's some security settings that mean a user has access only to the first url.

Is there a way to do this?

4

2 回答 2

3
get("/foo") {
  servletContext.getRequestDispatcher("/bar").forward(request, response)
} 
于 2011-09-30T01:17:04.733 回答
1

get() 方法定义为(类似于 POST 等):

def get(transformers : org.scalatra.RouteTransformer*)(action : => scala.Any) : org.scalatra.Route

取决于您所说的内部重定向的含义,我认为您只想执行另一条路线的操作。你有几个可以做的选择。这似乎对我有用:

val canonicalEndpoint = get("/first/route") {
  //do things in here    
}

然后您可以随后执行以下操作:

get("/second/route")( canonicalEndpoint.action )

我想你会得到你想要的回应。

我喜欢保存 get() 的整个 Route 响应,因为您可能还想在路由中使用 scalatra 的 url() 函数。

于 2014-04-16T22:24:01.970 回答