普通方法调用(随时增加)

普通方法调用(随时增加)

1.Map中的containsKey方法——判断是否包含指定的键名

Map m = new HashMap();

m.put("a","a");

m.put("b","b");

String key = "b";

boolean contains =m.containsKey(key);

    if (contains) {

   System.out.println("在Map集合中包含键名" + key);

    } else {

   System.out.println("在Map集合中不包含键名" + key);

    }

2.dom4j xml与字符串的转换等

  1.读取XML文件,获得document对象

     SAXReader reader = new SAXReader(); 

     Document   document = reader.read(new File("lijiahong.xml"));

  2.解析XML形式的文本,得到document对象.

     String text = "<lijiahong></lijiahong>";

     Document document = DocumentHelper.parseText(text);

  3.主动创建document对象.

     Document document = DocumentHelper.createDocument();             //创建根节点 

     Element root = document.addElement("lijiahong"); 

  4.节点相关

    1.获取文档的根节点.
      Element rootElm = document.getRootElement();
    2.取得某节点的单个子节点.
      Element memberElm=root.element("member");// "member"是节点名
    3.取得节点的文字
      String text=memberElm.getText();

    

3.java StringTokenizer使用方法

int countTokens():返回nextToken方法被调用的次数。
boolean hasMoreTokens():返回是否还有分隔符。
boolean hasMoreElements():返回是否还有分隔符。
String nextToken():返回从当前位置到下一个分隔符的字符串。
Object nextElement():返回从当前位置到下一个分隔符的字符串。
String nextToken(String delim):与4类似,以指定的分隔符返回结果。

String s=new String("The Java platform is the ideal platform for network computing");
StringTokenizer st=new StringTokenizer(s);
System.out.println("Token Total:"+st.countTokens());
while ( st.hasMoreElements() ){
System.out.println(st.nextToken());
}


String s=new String("The=Java=platform=is=the=ideal=platform=for=network=computing");
StringTokenizer st=new StringTokenizer(s,"=",true);
System.out.println("Token Total:"+st.countTokens());
while ( st.hasMoreElements() ){
System.out.println(st.nextToken());
}

4.jsp中跳转和js中重定向

href="javascript:window.location.href='url'"

window.location.href = "${basePath}/qiye/contact/person/select";

5.ajax返回map类型

$.ajax({
                cache: false,
                type: "POST",
                url:"${basePath}/qiye/contact/person/operationPerson",
                data:$('#blockForm').serialize(),
                async: false,
                error: function(data) {
                    alert("出现问题,请稍后再试");
                },
                success: function(msg) {
if(msg["state"] == "ok"){
//alert(msg["state"]);
alert("修改成功,即将跳转主页");
window.location.href = "${basePath}/qiye/contact/person/select";


}else
{
alert(msg["errmsg"]);
}

                      }
            });

6.Jquery怎么获取select选中项 自定义属性的值

("#select1  option:selected").attr("你定义的属性");
如果你的属性定义的是data-xxx,那么直接
("#select1 option:selected").data("xxx");



7.把request提交过来的参数放在一个map中


Map<String,Object> beanMap = req.getParameterMap();

8.遍历map

  for (Entry<String, Object> entry : beanMap.entrySet()) {
  System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
  }

9.map转javaBean
testBean t = new testBean();
Map m = new HashMap();
m.put("","");
BeanUtils.populate(t, map);