You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by worookie <wo...@hotmail.com> on 2003/06/17 08:50:28 UTC

any better way for charset encoding/decoding?

I have two web pages. Clients enter texts in a form on the first page. The
second page displays the entered text. The application is pretty simple. The
only troublesome part is that the entered text is encoded in Chinese
character-set (Big5 encoding), so we have to do some charset
encoding/decoding, otherwise the texts cannot be shown properly.

The following lists the java classes of the two pages.

========================================================
//The first page:

public class Registration extends BasePage {

 private String custName;
 public String getCustName() { return custName; }
 public void setCustName(String s) { custName = s; }

 public IMarkupWriter getResponseWriter(OutputStream out) {
  return new HTMLWriter("text/html;charset=Big5", out);
 }

 public void register(IRequestCycle cycle) {
  String custName = this.getCustName();

   Confirmation confirmationPage = (Confirmation)
cycle.getPage("Confirmation");
   try {
    custName = new String(custName.getBytes("ISO8859_1"), "Big5");
    confirmationPage.setStUserName(custName);
   } catch (UnsupportedEncodingException e) {
    System.out.println("e: " + e);
   }

   // Forward request to the "Confirmation" Page.
   cycle.activate("Confirmation");
 }
}

========================================================
// The second page:
public class Confirmation extends BasePage {

 private String stUserName;
 public String getStUserName() { return stUserName; }
 public void setStUserName(String s) { stUserName = s; }

 public IMarkupWriter getResponseWriter(OutputStream out) {
  return new HTMLWriter("text/html;charset=Big5", out);
 }

}

========================================================

As you can see, there will be a performance drop caused by the line of code:
    custName = new String(custName.getBytes("ISO8859_1"), "Big5");
where extra decoding and encoding operations happen.

Question: Is there any other better way to avoid the above line of code?
Thanks.

WORookie

Re: any better way for charset encoding/decoding?

Posted by worookie <wo...@hotmail.com>.
By the way, what I did is simply:

==========================================================

    public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
  throws IOException, ServletException {

        String encoding = ......
        if (encoding != null) {
   request.setCharacterEncoding(encoding);
   //response.setCharacterEncoding(encoding); // since Servlet v2.4
  }
        chain.doFilter(request, response);
    }

==========================================================

Will the above code cause any conflict or overlap with Tapestry's internal
code?

Thanks.

-Rookie


----- Original Message -----
From: "worookie" <wo...@hotmail.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Thursday, June 19, 2003 12:15 AM
Subject: Re: any better way for charset encoding/decoding?


> Well. A friend of mine told me to use a Filter to handle the charset
> encoding/decoding so that I don't need to do the transformation everywhere
> (in code). The Filter way works. My only concern is that Mindbridge and/or
> Howard is going to enhance/fix the charset encoding/decoding issues within
> the Tapestry structure. Will my own Filter way cause any conflict with
their
> work? Also, is the Filter workaround a good way to do with the new spec of
> Servlet 2.4 / JSP 2.0?
>
> Any comments will be highly appreciated.
>
> Regards,
>
> Rookie
>
> > ----- Original Message -----
> > From: "worookie" <wo...@hotmail.com>
> > To: "Tapestry users" <ta...@jakarta.apache.org>
> > Sent: Monday, June 16, 2003 11:50 PM
> > Subject: any better way for charset encoding/decoding?
> >
> >
> > > I have two web pages. Clients enter texts in a form on the first page.
> The
> > > second page displays the entered text. The application is pretty
simple.
> > The
> > > only troublesome part is that the entered text is encoded in Chinese
> > > character-set (Big5 encoding), so we have to do some charset
> > > encoding/decoding, otherwise the texts cannot be shown properly.
> > >
> > > The following lists the java classes of the two pages.
> > >
> > > ========================================================
> > > //The first page:
> > >
> > > public class Registration extends BasePage {
> > >
> > >  private String custName;
> > >  public String getCustName() { return custName; }
> > >  public void setCustName(String s) { custName = s; }
> > >
> > >  public IMarkupWriter getResponseWriter(OutputStream out) {
> > >   return new HTMLWriter("text/html;charset=Big5", out);
> > >  }
> > >
> > >  public void register(IRequestCycle cycle) {
> > >
> > >    Confirmation confirmationPage = (Confirmation)
> > > cycle.getPage("Confirmation");
> > >    try {
> > >     custName = new String(custName.getBytes("ISO8859_1"), "Big5");
> > >     confirmationPage.setStUserName(custName);
> > >    } catch (UnsupportedEncodingException e) {
> > >     System.out.println("e: " + e);
> > >    }
> > >
> > >    // Forward request to the "Confirmation" Page.
> > >    cycle.activate("Confirmation");
> > >  }
> > > }
> > >
> > > ========================================================
> > > // The second page:
> > > public class Confirmation extends BasePage {
> > >
> > >  private String stUserName;
> > >  public String getStUserName() { return stUserName; }
> > >  public void setStUserName(String s) { stUserName = s; }
> > >
> > >  public IMarkupWriter getResponseWriter(OutputStream out) {
> > >   return new HTMLWriter("text/html;charset=Big5", out);
> > >  }
> > >
> > > }
> > >
> > > ========================================================
> > >
> > > As you can see, there will be a performance drop caused by the line of
> > code:
> > >     custName = new String(custName.getBytes("ISO8859_1"), "Big5");
> > > where extra decoding and encoding operations happen.
> > >
> > > Question: Is there any other better way to avoid the above line of
code?
> > > Thanks.
> > >
> > > WORookie
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: any better way for charset encoding/decoding?

Posted by worookie <wo...@hotmail.com>.
Well. A friend of mine told me to use a Filter to handle the charset
encoding/decoding so that I don't need to do the transformation everywhere
(in code). The Filter way works. My only concern is that Mindbridge and/or
Howard is going to enhance/fix the charset encoding/decoding issues within
the Tapestry structure. Will my own Filter way cause any conflict with their
work? Also, is the Filter workaround a good way to do with the new spec of
Servlet 2.4 / JSP 2.0?

Any comments will be highly appreciated.

Regards,

Rookie

> ----- Original Message -----
> From: "worookie" <wo...@hotmail.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Monday, June 16, 2003 11:50 PM
> Subject: any better way for charset encoding/decoding?
>
>
> > I have two web pages. Clients enter texts in a form on the first page.
The
> > second page displays the entered text. The application is pretty simple.
> The
> > only troublesome part is that the entered text is encoded in Chinese
> > character-set (Big5 encoding), so we have to do some charset
> > encoding/decoding, otherwise the texts cannot be shown properly.
> >
> > The following lists the java classes of the two pages.
> >
> > ========================================================
> > //The first page:
> >
> > public class Registration extends BasePage {
> >
> >  private String custName;
> >  public String getCustName() { return custName; }
> >  public void setCustName(String s) { custName = s; }
> >
> >  public IMarkupWriter getResponseWriter(OutputStream out) {
> >   return new HTMLWriter("text/html;charset=Big5", out);
> >  }
> >
> >  public void register(IRequestCycle cycle) {
> >
> >    Confirmation confirmationPage = (Confirmation)
> > cycle.getPage("Confirmation");
> >    try {
> >     custName = new String(custName.getBytes("ISO8859_1"), "Big5");
> >     confirmationPage.setStUserName(custName);
> >    } catch (UnsupportedEncodingException e) {
> >     System.out.println("e: " + e);
> >    }
> >
> >    // Forward request to the "Confirmation" Page.
> >    cycle.activate("Confirmation");
> >  }
> > }
> >
> > ========================================================
> > // The second page:
> > public class Confirmation extends BasePage {
> >
> >  private String stUserName;
> >  public String getStUserName() { return stUserName; }
> >  public void setStUserName(String s) { stUserName = s; }
> >
> >  public IMarkupWriter getResponseWriter(OutputStream out) {
> >   return new HTMLWriter("text/html;charset=Big5", out);
> >  }
> >
> > }
> >
> > ========================================================
> >
> > As you can see, there will be a performance drop caused by the line of
> code:
> >     custName = new String(custName.getBytes("ISO8859_1"), "Big5");
> > where extra decoding and encoding operations happen.
> >
> > Question: Is there any other better way to avoid the above line of code?
> > Thanks.
> >
> > WORookie
> >
>

Re: any better way for charset encoding/decoding?

Posted by worookie <wo...@hotmail.com>.
----- Original Message -----
From: "worookie" <wo...@hotmail.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Monday, June 16, 2003 11:50 PM
Subject: any better way for charset encoding/decoding?


> I have two web pages. Clients enter texts in a form on the first page. The
> second page displays the entered text. The application is pretty simple.
The
> only troublesome part is that the entered text is encoded in Chinese
> character-set (Big5 encoding), so we have to do some charset
> encoding/decoding, otherwise the texts cannot be shown properly.
>
> The following lists the java classes of the two pages.
>
> ========================================================
> //The first page:
>
> public class Registration extends BasePage {
>
>  private String custName;
>  public String getCustName() { return custName; }
>  public void setCustName(String s) { custName = s; }
>
>  public IMarkupWriter getResponseWriter(OutputStream out) {
>   return new HTMLWriter("text/html;charset=Big5", out);
>  }
>
>  public void register(IRequestCycle cycle) {
>   String custName = this.getCustName();

sorry, please ignore the above line of code.

>
>    Confirmation confirmationPage = (Confirmation)
> cycle.getPage("Confirmation");
>    try {
>     custName = new String(custName.getBytes("ISO8859_1"), "Big5");
>     confirmationPage.setStUserName(custName);
>    } catch (UnsupportedEncodingException e) {
>     System.out.println("e: " + e);
>    }
>
>    // Forward request to the "Confirmation" Page.
>    cycle.activate("Confirmation");
>  }
> }
>
> ========================================================
> // The second page:
> public class Confirmation extends BasePage {
>
>  private String stUserName;
>  public String getStUserName() { return stUserName; }
>  public void setStUserName(String s) { stUserName = s; }
>
>  public IMarkupWriter getResponseWriter(OutputStream out) {
>   return new HTMLWriter("text/html;charset=Big5", out);
>  }
>
> }
>
> ========================================================
>
> As you can see, there will be a performance drop caused by the line of
code:
>     custName = new String(custName.getBytes("ISO8859_1"), "Big5");
> where extra decoding and encoding operations happen.
>
> Question: Is there any other better way to avoid the above line of code?
> Thanks.
>
> WORookie
>