1

I upload HTML file into DB as byte[] in blob column, and in another part I have to retrieve this file and display in textarea, I'm able to retrieve from DB as bytes and convert it into string, but when display its shows as encrypt format.

This is the struts application:

This is my jsp:

<tr>
 <td colspan="3" class="searchinput">   
      <html:textarea property="template" cols="100" rows="10" name="sendEmailForm">
      </html:textarea>
 </td>
</tr>

This is my form bean:

private String template = null;
public String getTemplate() {
   return template;
}

public void setTemplate(String template) {
   this.template = template;
}

This is my bean:

private byte[] templateContent = null;

public String getHtmlTemplateContent() {
  return templateContent.toString();
}

public byte[] getTemplateContent() {
  return templateContent;
}

public void setTemplateContent(byte[] templateContent) {
  this.templateContent = templateContent;
}

public void setTemplateContent(Object templateContent) {
  this.templateContent = (byte[])templateContent;
}

This is my action:

templatesDataBean = (TemplatesDataBean)SendEmailManager.getTemplate(action, actor, sendEmailBean);
sendEmailForm.setTemplate(new String(templatesDataBean.getHtmlTemplateContent()));

How can this can be solved? Thanks in advance.

4
  • Is it the possibility of encoding perhaps? Commented Nov 12, 2010 at 10:20
  • What do you mean by "encrypt data"? Commented Nov 12, 2010 at 11:04
  • Why do you need it as a byte[] in the first place? If it's HTML, a plain String should work all the way. Or doesn't your DB support storing string to the DB? ;) Commented Nov 12, 2010 at 11:19
  • shouldn’t this get encoded as UTF-8? Commented Nov 13, 2010 at 14:21

1 Answer 1

2

Seems like escapeXML issue. By default it is true. I couldn't find nothing for Classic Struts. BTW, there is an attribute in Struts2 named escape for <s:property> element. However, you can achieve this using JSTL.

<tr>
 <td colspan="3" class="searchinput">   
      <textarea cols="100" rows="10">
           <c:out value="${sendEmailForm.template}" escapeXml="false"/>
      </textarea>
 </td>
</tr>

And I believe, even this should also work like charm.

<tr>
 <td colspan="3" class="searchinput">   
      <textarea cols="100" rows="10">
           ${sendEmailForm.template}
      </textarea>
 </td>
</tr>

In case it's some encoding issue, try instantiating your String using this constructor.

new String(templatesDataBean.getHtmlTemplateContent(), Charset.UTF-8)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.