2016-04-24 4 views
1

Я разработал веб-сайт с j2ee. У меня не было проблем с кодировкой символов в моей среде разработки, но когда я развертываю свое приложение в openshift (jboss 7, mysql 5.5), форматирование UTF, похоже, не работает. Я попытался выполнить регистрацию на стороне сервера и, похоже, это проблема с jboss, поскольку я вижу, что сервлет не может декодировать символы. Пожалуйста, найдите код для front/backend ниже, после кодов, я перечислю то, что я уже пробовал.Openshift Кодировка символов JBoss

Спасибо,

  <form role="form" id="createadform" name="createadform" action="createads" method="POST" enctype="multipart/form-data"> 

<div class="row" > 
    <div class="col-md-6 col-md-offset-3" > 

     <div class="panel panel-primary"> 

     <div class="panel-heading"> 
     <h3 class="panel-title">Aşağıdaki formu doldurarak ilanınızı oluşturabilirsiniz.</h3> 

    </div>  

      <div class="panel-body "> 


      <div class="col-md-6" > 

    <div class="form-group has-feedback" style="width: 100%"> 
    <label for="isim">Başlık (En fazla 25 karakter)</label> 
    <input type="text" class="form-control" id="headline" name="headline" maxlength="25" required> 
    </div> 

    <div class="form-group has-feedback"> 
    <label for="minSalary">Maaş Alt Sınırı</label> 
    <input type="number" class="form-control" id="minsalary" name="minsalary" required> 
    </div> 
     <div class="form-group has-feedback"> 
    <label for="maxSalary">Maaş Üst Sınırı</label> 
    <input type="number" class="form-control" id="maxsalary" name="maxsalary" required> 
    </div> 
     <div class="form-group has-feedback"> 
    <label for="currency">Para Birimi</label> 
    <select class="form-control" id="currency" name="currency"> 
     <c:forEach var="currency" items="${currencies}"> 
      <option name="currency" value=${currency.currencyid}>${currency.currencydescription} </option> 
     </c:forEach> 
    </select> 
    </div> 
    <div class="form-group has-feedback" > 
    <label for="city">Şehir</label> 
    <select class="form-control" id="city" name="city"> 
    <c:forEach var="city" items="${cities}"> 
      <option name="city" value=${city.plateno}>${city.name} </option> 
    </c:forEach> 
    </select> 
    </div> 
    <div class="form-group has-feedback"> 
    <label for="worktype">İş tipi</label> 
    <select class="form-control" id="worktype" name="worktype"> 
     <c:forEach var="worktype" items="${worktypes}"> 
      <option name="worktype" value=${worktype.worktypeid}>${worktype.name} </option> 
    </c:forEach> 
    </select> 
    </div> 
<div class="col-md-6 text-center"> 
      <input type="file" name="resim" id="resim" accept="image/*"/> 
     </div> 
</div> 

       <div class="col-md-6" > 
     <div class="form-group has-feedback"> 
    <label for="freetext">İş Tanımı</label> 
    <textarea class="form-control" style="height: 300px;" id="freetext" name="freetext"></textarea> 
    </div> 


     <button type="submit" style="float: right; " class="btn btn-info ">Kaydı oluştur</button> 
     </div> 
     </div>   
     </div>  


</div> 
</div> 
      </form> 

У меня также есть JavaScript для проверки расширения файла:

<script> 

$("#createadform").submit(function(e){ 

     e.preventDefault(); 
     var resim = $('resim'); 
     var headline = $('headline'); 
     var minsalary = $('minsalary'); 
     var maxsalary = $('maxsalary'); 
     var currency = $('currency'); 
     var city = $('city'); 
     var worktype = $('worktype'); 
     var freetext = $('freetext'); 

     if ($('#resim').hasExtension(['.jpg', '.jpeg', '.bmp', '.gif', '.png'])) { 
     this.submit(); 
}else{ 
    alert("Seçeceğiniz resim için 'jpg, jpeg,bmp,gif ve png' formatlarını kullanabilirsiniz."); 
} 

}); 
</script> 

Мой сервлет код:

response.setContentType("text/html;charset=UTF-8"); 
      response.setCharacterEncoding("UTF-8"); 
      request.setCharacterEncoding("UTF-8"); 

Part resim = request.getPart("resim"); 
      InputStream is = resim.getInputStream(); 
      String resimFilename = FileUtilities.getFileName(resim); 
      String headline = request.getParameter("headline"); 
      String freetext = request.getParameter("freetext"); 
      System.out.println("FREETEXT in servlet : " + freetext); 
      int minsalary = Integer.parseInt(request.getParameter("minsalary")); 
      int maxsalary = Integer.parseInt(request.getParameter("maxsalary")); 
      int currencyId = Integer.parseInt(request.getParameter("currency")); 
      int cityId = Integer.parseInt(request.getParameter("city")); 
      int worktype = Integer.parseInt(request.getParameter("worktype")); 
      Person user = (Person) request.getSession().getAttribute("user"); 
      int employeeId = user.getPersonid(); 

Я добавил следующие свойства к моей автономной. xml файл:

<system-properties> 
     <property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="on"/> 
     <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> 

После этого я переместил эти свойства в конец файла, и jboss не смог запустить это время.

Также я создал файл pre_start_jbossas-7 в .openshift \ action_hooks папку и добавлены следующие строки в нем:

export JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.connector.URI_ENCODING=\"UTF-8\" \ 
        -Dorg.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING=\"true\"" 

EDIT 1:

Я также попытался это решение, оно Ждут» т.

Not able to set options in JAVA_OPTS in JBoss openshift

EDIT 2:

Я прочитал раздел для крюков действий сценариев и сделали их исполняемый файл и попытался снова развернуть, до сих пор не работает

ответ

2

Я решил эту проблему и хотел запишите его здесь на всякий случай, если кто-либо еще ищет ответ на ту же проблему.

Прежде всего, проблема заключалась в многопараметрических данных. Eventhough сервлет 3,0 апи позволял мне получать параметр с помощью

request.getParameter("parameterName") 

сервлет не может получить строки в формате UTF-8. Следовательно, я изменил эту строку со следующими строками, и это работает как шарм.

Part partname= request.getPart("parameterName"); 
InputStream is= partname.getInputStream(); 
String parameter = IOUtils.toString(is, "UTF-8"); 
Смежные вопросы