title: How can I get UTF-8 text in action class when starting server in Struts 2?
body: <p>I'm developing a web application by Struts 2 using Hibernate.</p>
  <p>But I have a problem that When I start server and load website then my loading method in action will be called. But, It can't load UTF-8, instead of <code>&quot;Phương&quot;</code> I get <code>&quot;PH??NG&quot;</code> But in JSP page still display <code>&quot;Phương&quot;</code>. So that, when I execute my SQL query and it is (<code>from Posts WHERE topics like '%PH??NG PHÁP GIÁO D?C TR?%'</code>, so I cannot query to my database.</p>
  <p>My action class here:</p>
  <pre><code>public class PostsAction extends ActionSupport {
  private List&lt;HomeTopic&gt; homeTopics = new ArrayList&lt;HomeTopic&gt;();
  public List&lt;HomeTopic&gt; getHomeTopics() {
      return homeTopics;
  }
  
  public void setHomeTopics(List&lt;HomeTopic&gt; homeTopics) {
      this.homeTopics = homeTopics;
  }
  
  
  public void callHomeTopics(){
       Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction trans = session.beginTransaction();
      String[] list = {&quot;NEW – TIN TỨC TRẺ&quot;,&quot;Khu Vui Chơi Cho Trẻ&quot;,&quot;PHƯƠNG PHÁP GIÁO DỤC TRẺ&quot;,&quot;KỸ NĂNG – KINH NGHIỆM&quot;,&quot;Phòng Bệnh&quot;,&quot;Tập Tô Màu&quot;};
      for (int i = 0; i &lt; list.length; i++) {
              getTopics(session, trans, list[i]);
          }
  trans.commit();
      session.close();
  }
  
  public void getTopics(Session session, Transaction trans, String type) {
      String hql = &quot;from Posts WHERE topics like '%&quot; + type + &quot;%'&quot;;
      System.out.println(&quot;HQL: &quot; + hql);
      Query query = session.createQuery(hql);
      query.setMaxResults(3);
      List&lt;Posts&gt; t = (ArrayList&lt;Posts&gt;) query.list();
      HomeTopic h = new HomeTopic(type, t);
      System.out.println(&quot;List topics: &quot; + type + &quot; &quot; + t);
      homeTopics.add(h);
      session.flush();
  }
  </code></pre>
  <p><strong><code>HomeTopics.java</code> class:</strong></p>
  <pre><code> public class HomeTopic {
  
      private String nameTopic;
      private List&lt;Posts&gt; postList;
  
      public List&lt;Posts&gt; getPostList() {
          return postList;
      }
  
      public void setPostList(List&lt;Posts&gt; postList) {
          this.postList = postList;
      }
  
      public HomeTopic(String nameTopic, List&lt;Posts&gt; postList) {
          this.nameTopic = nameTopic;
          this.postList = postList;
      }
  
      public HomeTopic() {
      }
  
      @Override
      public String toString() {
          return &quot;HomeTopic{&quot; + &quot;nameTopic=&quot; + nameTopic + &quot;, postList=&quot; + postList + '}';
      }
  
      public String getNameTopic() {
          return nameTopic;
      }
  
      public void setNameTopic(String nameTopic) {
          this.nameTopic = nameTopic;
      }
  }
  </code></pre>
  <p>When I write main method to test It still display UTF-8. But whenever I start server and call <code>callHomeTopics()</code> method in browser the text will is <code>&quot;PH??NG PHÁP GIÁO D?C TR?&quot;</code>.</p>
  <p>But in JSP page still display <code>&quot;Phương Pháp Giáo Dục Trẻ&quot;</code>.
  Everything ok except my HQL query.</p>