2 Replies Latest reply on Jul 7, 2014 5:18 AM by Wind Wild

    how to set wildfly‘s uriencode?

    Wind Wild Newbie

      Hello everybody.

      today,i met a question,i write a test demo to test uriencode of wildfly.my demo as follow:

      i write a jsp,in this jsp,i use <a> to transe "username" to servlet TestEncoding.

      <%@ page language="java" contentType="text/html; charset=utf-8"

          pageEncoding="utf-8"%>

      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

      <html>

      <head>

      <meta http-equiv="Content-Type" content="text/html; utf-8">

      <title>Insert title here</title>

      </head>

      <body>

      <a href="TestEncoding?username=测试编码">测试编码</a>

      </body>

      </html>

       

      TestEncoding.java was writen as follow:

      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // TODO Auto-generated method stub

        request.setCharacterEncoding("UTF-8");

        response.setCharacterEncoding("UTF-8");

        //String testpara=new String(.getBytes("ISO-8859-1"),"utf-8");

        System.out.println(request.getParameter("username"));

        }

      i visit index.jsp with ie browser as follow:

      11.png

      click "测试代码" and we can see there isn't correct chinese on server.log:

      22.png

      but when i use other browser as google or filefox,the console print as follow:

      33.png

      and i know that on jboss 7,we can add configuration to standalone.xml to modify uriencode as follow:

      <system-properties>

              <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>@@@

              <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>

      </system-properties>

      on tomcat,we can add URIEncoding="UTF-8" to "<Connector ....>" to  modify uriencode.but i don't know how to modify it on wildfly.

      I try to modify the servlet's default-encode to utf-8 as follow:

      44.png

      but it dosen't work,who can tell me how to modify wildfly's uriencoding?

       

      i look forware to your anwser,Thanks!

        • 1. Re: how to set wildfly‘s uriencode?
          Stephen Coy Master

          Adding:

          <jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://www.jboss.org/j2ee/schema/jboss-web_8_0.xsd" >
              <default-encoding>UTF-8</default-encoding>
          </jboss-web>
          

          in jboss-web.xml in your applications should do the trick.

          • 2. Re: how to set wildfly‘s uriencode?
            Wind Wild Newbie

            Hi,Stephen Coy

            Thanks your reply firstly.

            But it seems to be not works,I'm doubt that it isn't the way to configure the URIEncoding of wildfly.

            Tomcat and JBoss AS 7configure the URIEncoding on Connector.

            I also want to know the wildfly default charset,ISO-8850-1 or UTF-8?

            the following is part of undertow's source:

             

            package io.undertow.server.handlers.form;

             

            import java.io.IOException;

            import java.net.URLDecoder;

            import java.nio.ByteBuffer;

            import io.undertow.UndertowLogger;

            import io.undertow.UndertowMessages;

            import io.undertow.UndertowOptions;

            import io.undertow.server.HttpHandler;

            import io.undertow.server.HttpServerExchange;

            import io.undertow.util.Headers;

            import io.undertow.util.SameThreadExecutor;

            import org.xnio.ChannelListener;

            import org.xnio.IoUtils;

            import org.xnio.Pooled;

            import org.xnio.channels.StreamSourceChannel;

             

            /**

            * Parser definition for form encoded data. This handler takes effect for any request that has a mime type

            * of application/x-www-form-urlencoded. The handler attaches a {@link FormDataParser} to the chain

            * that can parse the underlying form data asynchronously.

            *

            * @author Stuart Douglas

            */

            public class FormEncodedDataDefinition implements FormParserFactory.ParserDefinition {

             

                public static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";

                private String defaultEncoding = "ISO-8859-1";

            ......

             

            Does it show us that "ISO-8859-1" is wildfly‘s default charset?or URIEncoding?