Re: double byte encoding issue.
Keats Kirsch <[email protected]> Wed, 30 Aug 2006 13:46:02 -0400
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
Hey AC,
There are some notes about using Big5 encoding in the release notes.
I've included it below in case it is helpful.
As I understand it, there are two basic encoding issues, (1) the
encoding with which the file is stored, and (2) the encoding for the output.
The input encoding (1) is controlled by the "TemplateEncoding" property
which you can set in your webmacro.properties file, or via the system
properties collection (see http://webmacro.org/ConfiguringWebMacro).
The output encoding (2) is controlled in various ways. You can set the
TemplateOutputEncoding property in the properties file:
TemplateOutputEncoding=3DBig5
You can also specify the encoding explicitly in your Servlet. See the
following code sample from WMServlet:
public void writeTemplate (String templateName, java.io.OutputStream out,
String encoding, Context context)
throws java.io.IOException, ResourceException, PropertyException
{
if (encoding =3D=3D null)
encoding =3D getConfig(WMConstants.TEMPLATE_OUTPUT_ENCODING);
Template tmpl =3D getTemplate(templateName);
tmpl.write(out, encoding, context);
}
If you use different output encodings for different templates, you may
want to use the #param directive in your templates. WMServlet uses
predefined parameter names, TemplateEncoding, and
TemplateOutputEncoding. Look at the source for WMServlet.execute() for
how this works.
Hope this is helpful.
Keats
WebMacro 06-12-2000: RELEASE NOTES
This release fixes a couple of bugs: I'm rolling it up mainly to make
the character encoding fix available to more people.
* Character Encoding
To propertly internationalize characters in WebMacro you must:
1. Set the correct encoding on FastWriter when you create it. WMServlet
defaults to setting it to whatever the HttpServletRequest object asks
for so in WMServlet you may not need to do anything. If you run WM in
standalone mode you must specify the correct encoding when you create a
new FastWriter:
FastWriter fw =3D FastWriter.getInstance(out, "Big5");
For example.
2. If there is internationalized text in your templates then you must
also ensure that the templates are read in correctly by WebMacro. You do
this by setting
TemplateEncoding: Big5
or whatever in your WebMacro.properties. If yoru templates can be read
as UTF-8 (they're ASCII++) then you don't need to do anything.
AC wrote:
>
> Hi there,
>
> I was evaluating WebMacro with Servlet for one Web application,
> fulfilling both English and Big5 Chinese UI.
>
> It worked very well and I could see the great convenience and
> simplicity behind. However, when come to using a template for Chinese,
> I found all big5 characters in my .wm files were strangely encoded
> when viewing through a servlet. Wondering if this was experienced
> before and have had solution or fix developed.
>
> My environment:
>
> Windows 2000 Professional
>
> Tomcat Apache 5.5.16
>
> WebMacro 2.0 (build date, 1^st Nov 2005)
>
> Options I have tried:
>
> #1. use HttpServlet with WebMacro
> -------------------------------------------------------------------------=
--
>
> public class WMHello extends HttpServlet {
>
> ...
>
> public void init() ..{
>
> ..
>
> private WebMacro _wm =3D new WM();
>
> }
>
> public void doGet(HttpServletRequest req, HttpServletResponse res) .. {
>
> ....
>
> res.setContentType("text/html;charset=3Dbig5");
>
> res.setLocale(new Locale("tw",""));
>
> ....
>
> try {
>
> WebContext c =3D _wm.getWebContext(req,res);
>
> Template tmpl =3D _wm.getTemplate(WMFile);
>
> /* have tried all below options and none works */
>
> //tmpl.write(res.getOutputStream(), res.getCharacterEncoding(), c);
>
> //tmpl.write(res.getOutputStream(), "BIG5", c);
>
> tmpl.write(res.getOutputStream(), c);
>
>
> }
>
> catch (WebMacroException e) {
>
> throw new ServletException(e);
>
> ...
>
> }
>
> }
>
> #2, trying to directly use a WebMacro Servlet where =93public class
> WMServlet01 extends WMServlet()
> =93---------------------------------------------------
>
> =85
>
> out.println("<h2>hfdhfdsf </h2>=94);
>
> //trying to include one WM writer
>
> RequestDispatcher disp =3D req.getRequestDispatcher("/WMServlet01");
>
> disp.include(req, resp);
>
> out.println("<p>the end");
>
> =85=85..
>
> -------------------------------------------------------------------------
>
>
> Attached .wm template and screen captures for reference.
>
>
> Please let me know if more info if needed. Thanks for any help in advance.
>
>
> AC@hongkong
>
>
> << File: big5Problm.JPG >> << File: hello.wm >>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job ea=
sier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=
=3D121642
> ------------------------------------------------------------------------
>
> _______________________________________________
> Webmacro-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/webmacro-user
> =
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easi=
er
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D1=
21642