[英]Converting a Scala Session Object to a Java Session Object in Play Framework
Is there a way to convert the session object in scala to the session object in java in Play ?有没有办法将scala 中的会话对象转换为Play中 java中的会话对象?
I have a Model method
written in java
like :我有一个用java
编写的Model method
,例如:
public void DoSomething(Request request, Session session)
{
String fancyValue = request.getQueryString("userInput");
session.put("Some Fancy Stuff",fancyValue);
}
and a Controller
method written in scala
like:和一个用scala
编写的Controller
方法,如:
def showHomePage = Action { implicit request =>
val JRequest = play.core.j.JavaHelpers.createJavaRequest(request)
val JSession // conversion needed from request.session to play.mvc.Http.Session
new SomeModel().DoSomething(JRequest,JSession)
// would this include the updates done to the session in the java model?
Ok("Testing Stuff").withSession(session)
}
If you look at the docs of the JavaHelpers
package , you'll find a function createJavaContext
there.如果您查看JavaHelpers
包的文档,您会在那里找到一个函数createJavaContext
。 You can use that to obtain a play.mvc.Http.Context
, from which you can extract a play.mvc.Http.Request
and play.mvc.Http.Session
.您可以使用它来获取play.mvc.Http.Context
,您可以从中提取play.mvc.Http.Request
和play.mvc.Http.Session
。
val java_ctx = play.core.j.JavaHelpers.createJavaContext(request)
val java_request = java_ctx.request()
val java_session = java_ctx.session()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.