jsp和Action中Base64编码转换
jsp中用javascript将中文Base64转码, Action中再用Base64解码
javascript中使用webtoolkit.base64.js,下载地址http://www.webtoolkit.info/djs/webtoolkit.base64.js
相关介绍 http://www.webtoolkit.info/javascript-base64.html
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode : function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
&nb
相关文档:
在当前应用系统的web.xml里加入jsp-config代码:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<jsp-config>
< ......
<%@page import="com.opensymphony.xwork2.util.ValueStack"%><%
ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");
String aa = (String)vs.findValue("downloadContent");
response. ......
1 MySQL存储大容量的二进制文件的格式是blob,其实除了图片还可以存别的
2 要向数据库存储二进制的文件一定要把要存储的数据转换成二进制流
废话就不多说了,大家看看代码很容易明白,先来看一个app程序,当然首先您要在数据库中先建立一个用于保存图片的表和相应的列,数据格式为blob
package ......
tomcat 默认使用的字符集是ISO-8859-1,不支持中文字符,所以在现实中文时需要转换字符和设置字符集。
server.mxl改为<Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> ,添加代码转换字符String.getBytes("ISO-8859-1"),"UTF-8 ......
<%
Calendar rightNow = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String sysdate = format.format(rightNow.getTime());
int week = rightNow.get(rightNow.DAY_OF_WEEK);
String weekar ......