----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

maciek kaminski wrote:
>
> Hello,
> 
> Have you used jserv with charset other than ISO-8859-1?
> I can't find the way to make browser send correct charset information to jserv.
> Setting <form ... enctype="application/x-www-form-urlencoded; charset=Cp1250">
> does not help.
> 
> Do I miss something or is it browsers fault?
> 
> Maciek Kaminski                  [EMAIL PROTECTED]

That's common browsers fault. Current browsers sent the characters
in encoding of the page with the form, but don't specify
the charset parameter correctly.
But even if they do, JServ will not handle it correctly,
see the source.

So the only way is:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet
{
 public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
                   throws ServletException, IOException
 {
   response.setContentType("text/html; charset=windows-1250");
   PrintWriter out = response.getWriter();
   try {
        out.println("<HTML><BODY><FORM METHOD=POST><INPUT NAME=a><INPUT
TYPE=SUBMIT>");
   } catch (Exception ex)
{out.println(ex.getMessage());ex.printStackTrace(out);}
 }
 public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
                   throws ServletException, IOException
 {
  String bad = request.getParameter("a");
  String good = new String(bad.getBytes("ISO-8859-1"),"windows-1250");
  response.setContentType("text/html; charset=windows-1250");
  PrintWriter out = response.getWriter();
   try {
     out.println("<HTML><BODY>a="+good);
   } catch (Exception ex)
{out.println(ex.getMessage());ex.printStackTrace(out);}
 }
}  



Martin


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to