NLD

フォームからPOSTした値を文字化けせずに受け取る


実行環境は以下の通り。
Windows NT Workstation 4.0
java version "1.2.2"
JavaTM Servlet API 2.2
WebLogic Server 5.1
Internet Explorer 5


mojipost.html
<html><body>
<form method=post action="Mojibake">
<input type=input name="a">
<input type=submit value="pushIt">
</form>
</body></html>


Mojibake.java
import java.io.*;
import javax.servlet.http.*;
public class Sat extends HttpServlet
{

public void service
    ( HttpServletRequest request, HttpServletResponse response )
        throws ServletException, IOException
{
  try
  {
    response.setContentType( "text/html" );
    String a = new String((request.getParameter("a")).getBytes("8859_1"),"Shift_JIS");
    System.out.println( a );
  }
  catch( Exception e ) { }

}  //  service method ends...

}  //  class block ends...


mojipost.htmlから送られたデータを、Mojibakeクラスで受け取る。
その際、取得した値を適切な文字コードに変換する必要がある。
今回はWindowsでShift_JISを用いた。


2000.12.03 produceD bY NI-Lab.

NLD