Posted by 唧唧 | tags:
遍历
HashMap
以下通过程序来简单实践一下HashMap的的遍历
PS:如果要保持HashMap的遍历顺序和原插入顺序一致,可以使用LinkedHashMap,使用方法和HashMap一样,改一下声明即可:LinkedHashMap myMap = new LinkedHashMap(); 当然需要导入:java.util.LinkedHashMap
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class MapList {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap myMap = new HashMap();
myMap.put("hello", "你好");
myMap.put("bye", "再见");
myMap.put("thanks", "谢谢");
myMap.put("ok", "好的");
System.out.println("--------------------遍历key和value----------------------");
for(Iterator iter = myMap.entrySet().iterator();iter.hasNext();){
Map.Entry element = (Map.Entry)iter.next();
Object strKey = element.getKey();
Object strObj = element.getValue();
System.out.println("myMap.get(\""+strKey+"\")="+strObj);
}
System.out.println();
System.out.println("--------------------遍历整个HashMap----------------------");
Collection objs = myMap.entrySet();
for (Iterator iterator=objs.iterator(); iterator.hasNext();){
Object obj = iterator.next();
System.out.println(obj);
}
System.out.println();
System.out.println("--------------------遍历HashMap的key----------------------");
Collection keys = myMap.keySet();
for (Iterator iterator=keys.iterator(); iterator.hasNext();){
Object key = iterator.next();
System.out.println(key);
}
System.out.println();
System.out.println("--------------------遍历HashMap的value----------------------");
Collection values = myMap.values();
for (Iterator iterator=values.iterator(); iterator.hasNext();){
Object value = iterator.next();
System.out.println(value);
}
}
}
运行结果:
--------------------遍历key和value----------------------
myMap.get("hello")=你好
myMap.get("thanks")=谢谢
myMap.get("ok")=好的
myMap.get("bye")=再见
--------------------遍历整个HashMap----------------------
hello=你好
thanks=谢谢
ok=好的
bye=再见
...
Posted by 唧唧 | tags:
jdom
xml
事先需要从这里下载:http://www.jdom.org/dist/binary/ jdom api,导入build目录的 jdom.jar
JdomRWXML.java 源码:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
...
Posted by 唧唧 | tags:
今天开发项目中发现:request.getRealPath(arg0); 报警告:
The method getRealPath(String) from the type ServletRequest is deprecated
request.getRealPath("") 这个方法已经不推荐使用了,那代替它的是什么方法呢?
...
Posted by 积极 | tags:
vssplugin
今天用eclipse ganymede配置vssplugin_1.6.2的时候,在vss directry栏输后,提示Failed to create Ole Client. result = -2147221164,一直报错,很郁闷。
搞了半天,才发现VSS安装目录被我移动过了,注册表找不到执行文件了,重新安装Microsoft Visual SourceSafe 6.0后,问题得到解决!
VSS Plugin version 1.6.2 for Eclipse 3.3:http://vssplugin.sourceforge.net/
...
Posted by 唧唧 | tags:
验证码
演示:点击评论栏目的用户名文本框 即可显示 验证码http://www.javawind.net/5b016f381a9e3f16011a9ebe0b570002.jhtml
------------------------------------------------------------------------------------
package org.javawind.servlet;
...
Posted by 唧唧 | tags:
Hibernate
proxool
MySQL
注:本人用的MySQL是5.1版本,proxool0.9.0RC3,部分参数可能因为版本的差异而有所不同。如有疑问,请到论坛寻求帮助:http://www.javawind.net
1、在hibernate.cfg.xml同级目录下建立Proxool的配置文件 ProxoolConf.xml :
<?xml version="1.0" encoding="utf-8"?>
<something-else-entirely>
<proxool>
<alias>javawindPool</alias>
<driver-url>jdbc:mysql://localhost:3306/bbs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8</driver-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<driver-properties>
<property name="user" value="username****"/>
<property name="password" value="password****"/>
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<maximum-new-connections>20</maximum-new-connections>
<prototype-count>5</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>5</minimum-connection-count>
</proxool>
</something-else-entirely>
...
Posted by 唧唧 | tags:
many-to-one
本人的论坛程序(风信论坛)中 有用到这样的结构
post 帖子表 userInfo 用户表
------------------------------------------------------------------
pid (int) 主键 userId(int) 主键
..... .....
userId (int)
现在要 获取 post 表数据的时候 同时获取 userId 关联的 userInfo 表数据, 也就是常用的inner join
解决方法:
...
Posted by 唧唧 | tags:
Eclipse
Publishing
Tomcat
Publishing failed
Removing obsolete files from server...
Could not clean server of obsolete files: XML document structures must start and end within the same entity.
XML document structures must start and end within the same entity.
Could not publish server configuration: XML document structures must start and end within the same entity..
XML document structures must start and end within the same entity.
准备做论坛的Rss,撰写输出rss xml 的jsp文件后,无法启动 Tomcat 调试运行,解决方法探索ing..
按照错误信息,其字面意思是叫我移除废弃或者不合法的文件,我检查了很多遍,都没有发现有什么文件不该存在,xml文件格式也都正确,Eclipse 检验整个项目没有报错呀。就是无法启动Servers下的Tomcat 6.0,而直接通过Monitor Tomcat却能正常启动 Tomcat 和运行项目,真是郁闷至极!
...
Posted by 唧唧 | tags:
Resin
虚拟目录
域名
编辑Resin 安装目录下 的 conf/resin.conf
在 </cluster> 节点 的:
<!-- configures the default host, matching any host name -->
<host id="" root-directory=".">
...
Posted by 唧唧 | tags:
mysql
root
密码
今天突然想登陆 办公室工作机的 MySQL Query Browser 发觉密码不正确,奇怪,我一直都是用空密码或者某一个特定密码的
尝试多次,还是不正确!不管是啥问题了,当作忘记密码来处理吧
- 首先在 MySQL的安装目录下 新建一个pwdhf.txt, 输入文本:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('*****');
- 红色部份为 需要设置的新密码
- 用windows服务管理工具或任务管理器来停止MySQL服务 (任务管理器K掉 mysqld-nt 进程)
- Dos命令提示符到 MySQL安装目录下的bin目录 如我的是 D:\Program Files\MySQL\MySQL Server 5.1\bin
- 然后运行: mysqld-nt --init-file=../pwdhf.txt
- 执行完毕 停止MySQL数据库服务 (任务管理器K掉 mysqld-nt 进程),然后再重新以正常模式启动MYSQL 即可