这是资源的方法
@Provider
@Produces( MediaType.APPLICATION_JSON )
@Consumes( MediaType.APPLICATION_JSON )
@Path("auth")
public class AuthenticationResource {
/**
* Проверка наличия логина в базе данных
* @param credentials - даный получаемый из формы
*/
@POST
@PermitAll
@Path("username")
public Response authenticateUserName(UserCredentials credentials) {
EmployeeDao dao = new EmployeeDaoImpl();
Employee email = dao.loadEmployeeByFieldStr("email", credentials.getUsername());
if(email == null){
throw new DataNotFoundException(MessageException.NO_LOGIN.getMessageTxt("en"));
}
credentials.setUsername(email.getEmail());
Response response = Response.ok(credentials).build();
return response;
}
...
我需要获取将当前请求发送到此方法的客户端浏览器中安装的语言的名称。如何获得此值?
我需要从后端的resquestcontext或其他工具获取此信息。我不必发送将在其中编程客户端语言环境的JSON客户端。
不应为此应用程序专门前端部分进行编程,因为可以从请求中获取此信息。 ?
它帮助了我Getting the client locale in a jersey request
@POST
@PermitAll
@Path("username")
public Response authenticateUserName(UserCredentials credentials, @Context HttpServletRequest request) {
EmployeeDao dao = new EmployeeDaoImpl();
Employee email = dao.loadEmployeeByFieldStr("email", credentials.getUsername());
Locale locale = request.getLocale();
System.out.println(request.getLocale().toString());
System.out.println(locale);
if(email == null){
throw new DataNotFoundException(MessageException.NO_LOGIN.getMessageTxt(request.getLocale().toString()));
}
credentials.setUsername(email.getEmail());
Response response = Response.ok(credentials).build();
return response;
}
谢谢。