2012年9月7日金曜日

struts2 action type plainTextの使い方

struts.xml のファイルに

              <action class="testAction" method="test" name="test">   
         <result name="success" type="plainText">
           <param name="charSet" />UTF-8
           <param name="location" />/test.jsp
         </result>   
         </action>

actionの中に、responseでクライアントにデータを転送する
ServletActionContext.getResponse().setContentType ("text/html;charset=utf-8");
  PrintWriter out = ServletActionContext.getResponse().getWriter();
  out.print("test");
  out.flush();
  out.close();

<param name="charSet">UTF-8</param>の目的は、文字化けを防ぐのため


0 件のコメント:

コメントを投稿