下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、首先,在刚刚去的时候,对于手机这一块,我的大脑还是一片空白,从刚开始接触,我们就开始学习wml1.2的标签,开始一步一步的研究学习这些标签都有什么功能,完了,再经过不断的实践来验证这些功能,虽然这一部比较痛苦吧,自己还是坚持了下来,用了大概两周的时间,基本上算是把他搞懂了。让后再结合jsp实现动态编程。在这个项目中,框架是项目经理给我们搭好的,我们只是往里面添加东西,这点倒是没什么难的,手机毕竟是与电脑不同的,手机有他的限制性:屏幕小,还有最重要的的一点就是,带宽特别有限,所以显示图片,就必须得经过进一步的转化才能显示在手机上,在此用到了类import com.sun.image.codec.
2、jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGImageEncoder;具体代码实现如下public class ImgTypeConv private static final Log log = LogFactory.getLog(ImgTypeConv.class);public static final String IMG_FORMAT_DEFAULT = "GIF"public static final String IMG_FORMAT_GIF = "GIF"public static
3、 final String IMG_FORMAT_JPG = "JPG"public static final String IMG_FORMAT_PNG = "PNG"public static final String IMG_FORMAT_BMP = "BMP"private int iWidth = 50;private int iHeight = 100;private boolean bAutoResize = false;/private String sImgFormat = ImgTypeConv.IMG_FORMA
4、T_DEFAULT; /* * 转换类析构函数,用于初始化图片转换所需要相当函数。 */public ImgTypeConv(int iWidth,int iHeight,boolean bAutoResize,String sImgFormat)this.iWidth = iWidth;this.iHeight = iHeight;this.bAutoResize = bAutoResize;/this.sImgFormat = sImgFormat;/* * 转换图片文件格式后另存为指定的目录 * param sUrl 源图片文件名称 如: * param sDir 图片文件转换后存储路径
5、 如:c:abcaxx.jpg * return 成功返回true,失败返回false * throws Exception */public boolean Conv(String sUrl,String sDir) throws Exceptionboolean rtn = true;try URL url = new URL(sUrl);URLConnection conn = url.openConnection();Image image = ImageIO.read(conn.getInputStream();int _iWidth=0,_iHeight=0;if(this.bAu
6、toResize) double rate1 = (double) image.getWidth(null) / (double) iWidth; double rate2 = (double) image.getHeight(null) / (double) iHeight; double rate = rate1 > rate2 ? rate1 : rate2; _iWidth = (int) (double) image.getWidth(null) / rate); _iHeight = (int) (double) image.getHeight(null) / rate);
7、else_iWidth = iWidth;_iHeight = iHeight;BufferedImage tag = new BufferedImage(_iWidth, _iHeight , BufferedImage.TYPE_INT_RGB);tag.getGraphics().drawImage(image.getScaledInstance(_iWidth, _iHeight , Image.SCALE_SMOOTH), 0, 0, null); out = new (sDir);JPEGImageEncoder encoder = JPEGCodec.createJPEGEnco
8、der(out);encoder.encode(tag);out.close(); catch (Exception e) log.error("图片转换出错:"+e.getMessage();throw new Exception("图片转换出错:"+e.getMessage();return rtn;/* * param args * throws Exception */public static void main(String args) throws Exception /URL url = new URL("");Img
9、TypeConv imgTypeConv = new ImgTypeConv(80, 160, true, ImgTypeConv.IMG_FORMAT_DEFAULT);imgTypeConv.Conv("", "c:ss.gif");再有一个问题就是由于数据库中的好多信息都是html格式的文件和Word中的文档,而在手机上并不识别这些信息,因此必须经过进一步的转化才能显示,在解析html时就用到了正则表达式/* * 将HTML格式的字符串转换成Text格式 * param inputString Html格式字符串 * return */public
10、 static String Html2TextTitle(String inputString) String strArr = "!DOCTYPE","Font","P","html","head","body","meta","OBJECT","a","st1","b"Pattern p_style;Matcher m_style;for(int i=0;i<str
11、Arr.length;i+)String regEx_html = "</?"+strArri+">*?>" /定义HTML标签的正则表达式p_style = pile(regEx_html,Pattern.CASE_INSENSITIVE);m_style = p_style.matcher(inputString);inputString = m_style.replaceAll(""); /过滤html标签p_style = pile("<",Pattern.CASE_INSENSIT
12、IVE);m_style = p_style.matcher(inputString);inputString = m_style.replaceAll("<"); /过滤style标签p_style = pile(">",Pattern.CASE_INSENSITIVE);m_style = p_style.matcher(inputString);inputString = m_style.replaceAll(">"); /过滤style标签p_style = pile("&n
13、bsp;",Pattern.CASE_INSENSITIVE);m_style = p_style.matcher(inputString);inputString = m_style.replaceAll(""); /过滤style标签return inputString;在读取Word文档时,用到了一个开源的技术POI,他可以读取Word文档。Oracle 中有两类比较特殊的数据BLOB、CLOB,就目前我所知道的他可以存储图片格式、html格式文本。从数据库中提取出来必须得经过转换,才能使用,转换如下:public static String getClog
14、2Str(Object obj)String rtn=""if(obj != null)tryClob clob = (Clob)obj;Reader reader=clob.getCharacterStream();BufferedReader br=new BufferedReader(reader);String line=""while(line=br.readLine()!=null)rtn = rtn + line;catch(Exception e)log.error("CLOB类型转换成字符类型出错:"+e.getMe
15、ssage();return rtn;/* * 将Blob类型转换成字符串,具体功能请多多尝试。 * param obj Blob类型数据 * param * return * throws SQLException * throws IOException * author */public static String getBlob2Str(Object obj,String ) throws SQLException, IOExceptionString rtn=""if(obj != null)tryBlob imgblob=(Blob)obj;BufferedIn
16、putStream bis = new BufferedInputStream(imgblob.getBinaryStream();long ();int bufferSize =0;if( >0)bufferSize = Integer.parseInt(String.valueOf();if(bufferSize <= 0)log.error("文件大小太小(1)!");return null;String path=pt+; = new );if (!folder.exists()folder.mkdir();/创建文件夹:filesFile f = new ); out = new (f); byte buffer = new bytebufferSize; int bytesRead =bis.read(buffer); if(bytesRead <= 0)log.error("文件大小太小(2)!");return null;out.write(buffer); out.flush(); out.close(); bis.close(); rtn=TypeConv.getDoc2Str(path); catch(Exception e)l
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 45305.5-2026声学建筑构件隔声的实验室测量第5部分:测试设施和设备的要求
- 2026福建泉州市晋江市安海镇第三中心幼儿园招聘4人笔试参考题库及答案解析
- 2026浙江宁波前湾控股集团有限公司第1批次人员招聘考试参考试题及答案解析
- 2026心血管病遗传与分子机制湖北省重点实验室主任招聘(湖北)笔试模拟试题及答案解析
- 2026安徽合肥市人力资源服务有限公司派驻至合肥钢铁集团汽车运输有限责任公司工作人员招聘1人考试备考试题及答案解析
- 2026年黄山市人民医院招聘护理人员11名考试备考试题及答案解析
- 2026年池州九华山佛教协会公开招聘编外工作人员6名考试备考试题及答案解析
- 2026进贤县消防救援大队招聘3人考试备考题库及答案解析
- 2026上半年青海事业单位联考黄南州招聘68人考试参考题库及答案解析
- 2026年光伏-热电复合系统项目评估报告
- 江苏省无锡市2025-2026学年高三上学期期末考试英语试题(含答案)
- 山林共协议书范本
- 高考全国乙卷物理考试卷含解析及答案
- 2025化工安全事故案例
- 莫兰迪工作总结计划
- 2025年智能焊接机器人产业发展蓝皮书
- 中建总进度计划编排交流汇报
- 2025年四川省成都市中考英语真题(原卷版)
- DB43-T 2438-2022 党政机关治安反恐防范要求
- 介入治疗术前准备
- 市政道路监理质量评估报告
评论
0/150
提交评论