当前位置: 编程技术>移动开发
本页文章导读:
▪导出Excel乱码有关问题(少于2条出现乱码解决方案) 导出Excel乱码问题(少于2条出现乱码)
导出Excel格式的文件在网上已经有很多了了,先前都是用报表工具(jasperreport)来弄的,后来打算用opi,jxl,同事说那样子写代码会写很多,所以就用.........
▪ 小弟我学习移动开发的一个聊天程序 我学习移动开发的一个聊天程序
[size=large]Solution ReportProtocol define and explain We define the following a simple transportation protocol which the midlet send to server:Id_message_bodyThe first is the midlet’s id;The second .........
▪ Activity其间传递类对象 Activity之间传递类对象
Activity之间通过Intent传递值,支持基本数据类型和String对象及它们的数组对象byte、byte[]、char、char[]、boolean、boolean[]、short、short[]、int、int[]、long、long[]、float、float[]、.........
[1]导出Excel乱码有关问题(少于2条出现乱码解决方案)
来源: 互联网 发布时间: 2014-02-18
导出Excel乱码问题(少于2条出现乱码)
导出Excel格式的文件在网上已经有很多了了,先前都是用报表工具(jasperreport)来弄的,后来打算用opi,jxl,同事说那样子写代码会写很多,所以就用html代码来些,说是可以自动转换。
以下为转换的具体方法:
StringBuilder sb = new StringBuilder(2000);
以下为编码格式:
导出Excel格式的文件在网上已经有很多了了,先前都是用报表工具(jasperreport)来弄的,后来打算用opi,jxl,同事说那样子写代码会写很多,所以就用html代码来些,说是可以自动转换。
以下为转换的具体方法:
StringBuilder sb = new StringBuilder(2000);
sb.append("<html>"); sb.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'></head><body>");//这个必须设置,不然只有1条记录的时候,导出会出现乱码 sb.append("<table width='800' border='1' cellpadding='0' cellspacing='0' bordercolor='#000000'>"); sb.append("<caption>"); sb.append("<span >交接班日志列表</span>"); sb.append("</caption>"); sb.append("<tr>"); sb.append("<th width='149' bgcolor='#CCCCFF'>日期</th>"); sb.append("<th width='132' bgcolor='#CCCCFF'>当班时间</th>"); sb.append("<th width='126' bgcolor='#CCCCFF'>值班人</th>"); sb.append("<th width='112' bgcolor='#CCCCFF'>班组</th>"); sb.append("<th width='93' bgcolor='#CCCCFF'>班次</th>"); sb.append("<th width='148' bgcolor='#CCCCFF'>开始值班时间</th>"); sb.append("</tr>"); if (runOnwatchList != null) { listSize = runOnwatchList.size(); // 循环取出数据填充表格 for (int i = 0; i < listSize; i++) { sb.append("<tr>"); RunOnwatch runOnwatch = runOnwatchList.get(i); String[] data = new String[6]; data[0] = DateUtil.format(runOnwatch.getOnwatchdate()); data[1] = runOnwatch.getRunOnwatchorder().getStarttime() + "-" + runOnwatch.getRunOnwatchorder().getEndtime(); data[2] = runOnwatch.getOnwatchby(); data[3] = runOnwatch.getGroupname(); data[4] = runOnwatch.getGrouporder(); data[5] = DateUtil.format(runOnwatch.getStartwatchtime(), DateUtil.YMDHMS); for (int j = 0; j < 6; j++) { sb.append("<td align='left'>"); sb.append(data[j]); sb.append("</td>"); } sb.append("</tr>"); } } sb.append("</table>"); sb.append("</body></html>");;
以下为编码格式:
String fileName = java.net.URLEncoder.encode("交接班日志列表.xls", "UTF-8");//这个必须设置,不然导出另存为的时候,文件名会出现乱码(支持中文的) res.setHeader("Content-Type", "application/force-download"); res.setHeader("Content-Type", "application/vnd.ms-excel;charset='UTF-8'"); res.setHeader("Content-Disposition", "attachment;filename=" + fileName); res.setCharacterEncoding("UTF-8");//这个必须设置 PrintWriter pw = res.getWriter(); System.out.print("excelData=="+excelData); pw.write(excelData); pw.flush(); pw.close();
[2] 小弟我学习移动开发的一个聊天程序
来源: 互联网 发布时间: 2014-02-18
我学习移动开发的一个聊天程序
Protocol define and explain
We define the following a simple transportation protocol which the midlet send to server:
Id_message_body
The first is the midlet’s id;
The second is the method, it can be “add”,”message”,”delete”
The third part is the message;
Id_add_MessageBody: This message will be send by midlet when he connect to the chat room.
Id_message_MessageBody: This message will be send by midlet when he send a message to other.
Id_delete_MessageBody: This message will be send by midlet when he leave the chat room.
We define a simple transportation protocol which the server send to midlet:
messageType_messageBody
The first is the message Type, it can be “private”,”message”
The second is the messageBody.
Private_messageBody: This information will be send only for this person, and it will displayed at the top, for example, the previous connected person’s information.
Message_messageBody: This information will be send for all the person, and it will displayed as a chat history below the private message. For example, the other person’s chat message.
Server side implementation
We implement a servlet which will startup when the server is started, and the servlet will initialize a Thread which listened in 8000(You can configure it in configuration file web.xml). Every time when a new connection come in, a new Thread will create to deal with the message. And we maintain a Socket collection which hold all the socket connection.
Midlet client implementation
When the program initialized, it will construct a SocketConnection, and when user click the connect, we will create two thread, one is the writeThread which will write the message queue’s message to server, the other is the readThread, which will read the message from server, and display it in corresponding location according to the message type.
When the user click the send button, the message will be put into message queue, and it will notify the writeThread to write it to the server.
When the user click the exit button, the readThread and the writeThread will be stoped, and also we will release some resources, for example the socket’s InputStream and OutputStream, and also the SocketConnection.
[/size]
嗯, J2ME的thread还真麻烦...
Java SE和EE都开发过,但ME没有开发过,我稍微看了一下,然后按照开发java程序的思想写的,但感觉稍微不一样。
是在说我吗? 要是我的话,先谢谢了。
字体调大了省眼睛呀,呵呵。
感谢一下,写的不是很好,欢迎交流。
[size=large]Solution Report
Protocol define and explain
We define the following a simple transportation protocol which the midlet send to server:
Id_message_body
The first is the midlet’s id;
The second is the method, it can be “add”,”message”,”delete”
The third part is the message;
Id_add_MessageBody: This message will be send by midlet when he connect to the chat room.
Id_message_MessageBody: This message will be send by midlet when he send a message to other.
Id_delete_MessageBody: This message will be send by midlet when he leave the chat room.
We define a simple transportation protocol which the server send to midlet:
messageType_messageBody
The first is the message Type, it can be “private”,”message”
The second is the messageBody.
Private_messageBody: This information will be send only for this person, and it will displayed at the top, for example, the previous connected person’s information.
Message_messageBody: This information will be send for all the person, and it will displayed as a chat history below the private message. For example, the other person’s chat message.
Server side implementation
We implement a servlet which will startup when the server is started, and the servlet will initialize a Thread which listened in 8000(You can configure it in configuration file web.xml). Every time when a new connection come in, a new Thread will create to deal with the message. And we maintain a Socket collection which hold all the socket connection.
Midlet client implementation
When the program initialized, it will construct a SocketConnection, and when user click the connect, we will create two thread, one is the writeThread which will write the message queue’s message to server, the other is the readThread, which will read the message from server, and display it in corresponding location according to the message type.
When the user click the send button, the message will be put into message queue, and it will notify the writeThread to write it to the server.
When the user click the exit button, the readThread and the writeThread will be stoped, and also we will release some resources, for example the socket’s InputStream and OutputStream, and also the SocketConnection.
[/size]
1 楼
asialee
2009-08-03
对不起呀,这个是我给一个留学的同学做的,大家就勉强的看吧。也随便锻炼锻炼英文,呵呵。
2 楼
ccxw1983
2009-08-03
确实不错哦,英文好啊
3 楼
asialee
2009-08-04
做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
4 楼
lordhong
2009-08-04
asialee 写道
做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
嗯, J2ME的thread还真麻烦...
5 楼
wayfarer
2009-08-04
怎么麻烦了?我觉得还好啊
嗯, J2ME的thread还真麻烦...
lordhong 写道
asialee 写道
做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
嗯, J2ME的thread还真麻烦...
6 楼
asialee
2009-08-04
wayfarer 写道
怎么麻烦了?我觉得还好啊
嗯, J2ME的thread还真麻烦...
lordhong 写道
asialee 写道
做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
嗯, J2ME的thread还真麻烦...
Java SE和EE都开发过,但ME没有开发过,我稍微看了一下,然后按照开发java程序的思想写的,但感觉稍微不一样。
7 楼
youngmaster
2009-08-04
看了朋友的作品,感觉真好...期待朋友更多的精彩!
8 楼
asialee
2009-08-04
youngmaster 写道
看了朋友的作品,感觉真好...期待朋友更多的精彩!
是在说我吗? 要是我的话,先谢谢了。
9 楼
asialee
2009-08-05
这个是我用了大概3天时间写的,还是比较仓促。当感觉思想是相通的。
10 楼
asialee
2009-08-05
这么多人下载了,小弟感谢一下,也欢迎大家提点意见。
11 楼
java.lang.Object
2009-08-05
楼主netbeans的代码字体调得真大。
12 楼
asialee
2009-08-06
java.lang.Object 写道
楼主netbeans的代码字体调得真大。
字体调大了省眼睛呀,呵呵。
13 楼
asialee
2009-08-17
写了这么一个烂程序被下载了上千次,我以后还会上传我的一些小程序的,不过质量会更好的。
14 楼
菩萨Lu
2010-05-31
刚开始接触j2me,拿走研究学习了,thx
15 楼
asialee
2010-06-01
菩萨Lu 写道
刚开始接触j2me,拿走研究学习了,thx
感谢一下,写的不是很好,欢迎交流。
[3] Activity其间传递类对象
来源: 互联网 发布时间: 2014-02-18
Activity之间传递类对象
Activity之间通过Intent传递值,支持基本数据类型和String对象及它们的数组对象byte、byte[]、char、char[]、boolean、boolean[]、short、short[]、int、int[]、long、long[]、float、float[]、double、double[]、String、String[],还有实现Serializable、Parcelable接口的类对象。
传递类对象以前一直没搞懂怎么做,都是用静态引用。现在终于搞懂了,实现Serializable接口,废话少说,看代码。
传递的类
public class CustomeClass implements Serializable{ /** * */ private static final long serialVersionUID = -7060210544600464481L; private String name; private String id; private int age; private String sex; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } }
发送部分
CustomeClass cc = new CustomeClass(); cc.setAge(21); cc.setId("123456"); cc.setName("mingkg21"); cc.setSex("男"); Intent intent = new Intent(this, PersonInfo.class); intent.putExtra("PERSON_INFO", cc); startActivity(intent);
接收部分
Intent intent = getIntent(); CustomeClass cc = CustomeClass)intent.getSerializableExtra("PERSON_INFO"); setTextView(R.id.id, cc.getId()); setTextView(R.id.name, cc.getName()); setTextView(R.id.sex, cc.getSex()); setTextView(R.id.age, String.valueOf(cc.getAge()));
搞定,打完收工。。。
1 楼
fanfq
2009-10-28
要是传递一个List该怎么做啊?我也尝试了,但是不行了啊,还望请教
CustomeClass cc = new CustomeClass();
cc.setAge(21);
cc.setId("123456");
cc.setName("mingkg21");
cc.setSex("男");
List<CustomeClass> list = new ArrayList<CustomeClass>();
list.add(cc);
Intent intent = new Intent(this, PersonInfo.class);
intent.putExtra("PERSON_INFO", list);
startActivity(intent);
我是这么想的,但是不行的哇,
CustomeClass cc = new CustomeClass();
cc.setAge(21);
cc.setId("123456");
cc.setName("mingkg21");
cc.setSex("男");
List<CustomeClass> list = new ArrayList<CustomeClass>();
list.add(cc);
Intent intent = new Intent(this, PersonInfo.class);
intent.putExtra("PERSON_INFO", list);
startActivity(intent);
我是这么想的,但是不行的哇,
2 楼
mingkg21
2009-10-28
用Serializable接口传递对象
http://mingkg21.iteye.com/admin/blogs/463895
发送部分
接收部分
http://mingkg21.iteye.com/admin/blogs/463895
发送部分
CustomeParcelable cc = new CustomeParcelable(); cc.setAge(21); cc.setId("123456"); cc.setName("mingkg21"); cc.setSex("男"); ArrayList<CustomeParcelable> list = new ArrayList<CustomeParcelable>(); list.add(cc); Intent intent = new Intent(this, PersonInfo.class); intent.putParcelableArrayListExtra("PERSON_INFO", cc); startActivity(intent);
接收部分
Intent intent = getIntent(); ArrayList<CustomeParcelable> list = new ArrayList<CustomeParcelable>(); list = intent.getExtras().getParcelableArrayList("PERSON_INFO");
3 楼
mingkg21
2009-10-28
上面写错了。。。
用Parcelable接口传递对象
用Parcelable接口传递对象
4 楼
pgmsoul
2011-06-20
PersonInfo是什么东西?
最新技术文章: