struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Delbecq <de...@oma.be>
Subject Re: Could struts be corrupting my byte[]?
Date Mon, 12 Sep 2005 14:05:56 GMT
As far as i read, you are using an html:text field along a form property of type byte[]
eg: you type "Hello World" an you want your form to store 
byte[] b={72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}

If that's the case, i think declaring the field descricao as a byte in your struts form
is not a good idea. Your should declare it as a String and convert it to byte[]
when you reach the hibernate level. To keep with your example, this mean
a prototype in your form like this:
public String getDescricao();
public void setDescricao(String);

Then you can transfer to cor like this
cor.setDescricao(addCorForm.getDescricao().getBytes("UTF-8"));

and you can get back from cor like this:
String s = new String(cor.getDescricao(),"UTF-8");

why? Because if you do not specify the character encoding when
you are converting between bytes and String, you use the platform
dependent character encoding, which may leads you in problems if this
platform dependent encoding change (eg. moving you webserver from 
windows to unix)

Also someone suggested you check the character encoding of client http request,
as an additional comment on that suggestion, i'll suggest you try to use the 
accept-encoding parameter of the <form> tag.

Hope this helps

Le Lundi 12 Septembre 2005 14:35, Letícia Álvares Barbalho a écrit :
> 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
> 
> 
> 
> 
> 
> 

-- 
David Delbecq
Royal Meteorological Institute of Belgium

-
Is there life after /sbin/halt -p?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message