将 HTML 文件的 byte[] 转换为 String
我将 HTML 文件作为 blob 列中的 byte[] 上传到数据库中,在另一部分中,我必须检索该文件并在文本区域中显示,我能够从数据库中检索字节并将其转换为字符串,但是当显示它时作为加密格式。
这是 struts 应用程序:
这是我的 jsp:
<tr>
<td colspan="3" class="searchinput">
<html:textarea property="template" cols="100" rows="10" name="sendEmailForm">
</html:textarea>
</td>
</tr>
这是我的表单 bean:
private String template = null;
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
这是我的 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;
}
这是我的操作:
templatesDataBean = (TemplatesDataBean)SendEmailManager.getTemplate(action, actor, sendEmailBean);
sendEmailForm.setTemplate(new String(templatesDataBean.getHtmlTemplateContent()));
这如何解决?提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎是
escapeXML
问题。默认情况下它是true
。我找不到 Classic Struts 的任何内容。顺便说一句,Struts2 中有一个用于
元素的名为escape
的属性
。不过,您可以使用 JSTL 来实现这一点。我相信,即使这样也应该像魅力一样发挥作用。
如果存在一些编码问题,请尝试使用此构造函数实例化您的
String
。Seems like
escapeXML
issue. By default it istrue
. I couldn't find nothing for Classic Struts. BTW, there is anattribute
in Struts2 namedescape
for<s:property>
element. However, you can achieve this using JSTL.And I believe, even this should also work like charm.
In case it's some encoding issue, try instantiating your
String
using this constructor.