It sounds like you are probably a victim of the ill-defined rules for handling character encoding between web browser and web servers. These rules are gradually being better defined, but there's still a fair amount of grey.

For starters, there is no standard way to indicate in your HTML how you want the request parameters encoded when they are sent to you. There's an attribute of <form> but most browsers have not implemented support for it. What is standard in practice is that the browser will return values to you in the same encoding that you delivered the form page.

Once you have taken care to make sure that browser will send you values with the right encoding, you then need to tell your servlet container what encoding that will be. Before Servlet 2.3, this is something that is done with container-specific configuration. Beginning with Servlet 2.3, the HttpServletRequest has a "setCharacterEncoding" method which will control how the request parameter bytes are deserialized into Java strings. You *must* set this value before any data is read from the request input stream, either by you or by Java code on your behalf. Because of this, Servlet Filters are the best way to handle this. In fact, this problem is so wide spread and the solution so commonly accepted that the most common example code for ServletFilters is probably to solve this very problem.

In your case, since you are handling the values in the action after Struts has already populated the form, it's too late to correct the corruption caused by using the wrong character encoding.

Now that Struts 1.3 is based on Servlet 2.3, I propose that we add a typical implementation of this filter to the distribution, just to make people's lives easier. I probably won't get to it for a while, so if anyone else is interested, please feel free.

Joe



At 9:35 AM -0300 9/12/05, Letícia Álvares Barbalho wrote:
Hello, everyone.

I have an app which uses struts + hibernate. I was having a problem of
corrupted blobs (which are treated by the app as byte[]), and so far I was
blaming hibernate for that. But right now, making a test, I found out that
my data gets corrupted BEFORE even being treated by hibernate. Here's what I
have:

1. A jsp page that gets a String using html:text, property = descricao
2. An action form that has the descricao property as a byte[], together with
its getters and setters
3. An action that takes data from this action form and puts it in my object,
which by the way also has this property as a byte[], with its getters and
setters.

So, what I wanna do is get this String and put in a blob field. Here comes
my action code:

cor.setCor(addCorForm.getCor());
cor.setNome(addCorForm.getNome());
cor.setDescricao(addCorForm.getDescricao());
CorService.getInstance().addCor(cor);

That's basically it: I set the properties and add. The thing is that if I
get the byte[] value of addCorForm.getDescricao() and convert it to a
string, it gives me NULL or a lot of weird characters. That means my data is
getting corrupted right there, before its insertion.

Another proof of it, is that if I insert a line in this table using the
database's tool, I can retrieve the information through my application.

So... database tool = correct data. App = incorrect data, even before adding
the object in the DB with hibernate. What I can think here is struts is
corrupting... could it be?

1. Is html:text the correct component I have to use for this?
2. Do I have to make any conversion, being that I insert a String and it
gets a byte[]?

How do you guys do it? Thank you all very much for the help






--
Letícia Álvares Barbalho
[EMAIL PROTECTED]


--
Joe Germuska
[EMAIL PROTECTED]
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction"  -The Ex

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to