Wrong Charset Encoding with Play Framework 2.1

拟墨画扇 提交于 2020-01-04 14:22:12

问题


I have a web service that receives a parameter in ISO-8859-1 encoding.

But when I try to read it from the request, I get this characters:

�����

I've tryied all these approaches, but none of the convert the given string to the expected one (áéíóú):

    val a = new String(_html.getBytes());
    val b = new String(_html.getBytes(), "UTF-8")
    val c = new String(_html.getBytes(), "ISO-8859-1")
    val d = new String(_html.getBytes("ISO-8859-1"), "UTF-8")
    val e = new String(_html.getBytes("ISO-8859-1"), "ISO-8859-1")
    val f = new String(_html.getBytes("UTF-8"), "UTF-8")
    val g = new String(_html.getBytes("UTF-8"), "ISO-8859-1")

Here is my action:

  val inboundMessageForm = Form(
    mapping(
      "html" -> text)(InboundMessage.apply)(InboundMessage.unapply))

  def forward = Action(parse.multipartFormData) { implicit request =>
    val inboundMessage = inboundMessageForm.bindFromRequest.get

        // inboundMessage.html =>  �����
   }

What can I do to solve this problem?


回答1:


Here is the answer to this question:

https://groups.google.com/forum/?fromgroups=#!topic/play-framework/R0ayxNuzR74




回答2:


If you are running windows, the default encoding (at least in the states, not sure about the rest of the world) is actually "windows-1252", not "ISO-8859-1". You could also try "UTF-16" in case those characters aren't included in the "UTF-8" encoding (which most things other than windows use).



来源:https://stackoverflow.com/questions/16044263/wrong-charset-encoding-with-play-framework-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!