zoukankan      html  css  js  c++  java
  • 2012年2月零碎笔记

    jscss以及html

    获得当前应用的路径

    System.out.println("request.getContextPath():"+request.getContextPath());

    System.out.println("request.getSession().getServletContext().getContextPath():"+request.getSession().getServletContext().getContextPath());

     

    HTML5的figure标签

    figure用来代替原来li标签,P标签谁来取代呢?答案就是:figcaption

    w3c赋予的定义:figure标签规定独立的流内容(图像、图表、照片、代码等等)。figure 元素的内容应该与主内容相关,但如果被删除,则不应对文档流产生影响。

     

    HTML <label> 标签的 for 属性

    定义和用法

    for 属性规定 label 与哪个表单元素绑定。

    隐式和显式的联系

    标记通常以下面两种方式中的一种来和表单控件相联系:将表单控件作为标记标签的内容,这样的就是隐式形式,或者为 <label> 标签下的 for 属性命名一个目标表单 id,这样就是显式形式。

    例如,在 XHTML 中:

    显式的联系:

    <label for="SSN">Social Security Number:</label>

    <input type="text" name="SocSecNum" id="SSn" />

    隐式的联系:

    <label>Date of Birth: <input type="text" name="DofB" /></label>

    第一个标记是以显式形式将文本 "Social Security Number:" 和表单的社会安全号码的文本输入控件 ("SocSecNum") 联系起来,它的 for 属性的值和控件的 id 一样,都是 SSN。第二个标记 ("Date of Birth:") 不需要 for 属性,它的相关控件也不需要 id 属性,它们是通过在 <label> 标签中放入 <input> 标签来隐式地连接起来的。

    实例

    带有两个输入字段和相关标记的简单 HTML 表单:

    <form>

    <label for="male">Male</label>

    <input type="radio" name="sex" id="male" />

    <br />

    <label for="female">Female</label>

    <input type="radio" name="sex" id="female" />

    </form>

     

    jQuery中设置form表单中action值的方法

    html代码:

    <form id="myFormIdname="myForm" action="" method="post">
      <input type="hidden" id="inParam" name="inParam" />
      <input type="hidden" id="tstype" name="tstype" />
      <input type="hidden" id="zd" name="zd" />
    </form>

    熟悉JavaScript的朋友一定晓得JS可以动态改变form表单中action的值,写法如下:

    document.myForm.action = "userinfo.shtml";   

    //需要注意的是form标签一定要有name属性,光有id没有name不起作用

     document.myForm.attributes["action"].value  = "XXXXXXXX";

    document.all("myFormId").setAttribute("action", "欲赋的action的值");

    上述两种方式在JavaScript中均经过测试。

    下面介绍在jQuery中设置form表单中action的值的方法。

    $("#myFormId").attr("action", "userinfo.shtml");

    【注意】:$("#myFormId").action="XXX";  这种写法是不起作用的!

    Jquery获取和设置元素value属性

    Jquery提供了获得和设置元素的value的方法。如input textarea等元素的value值。

    例子:<input name="a" id="a" value="Hello">

     1. val()获取元素的值。jquery不能直接使用value属性去操作元素的值。

        错误操作: var myvalue=$("#a").value;

        正确操作: var myvalue=$("#a").val();

       2. val("要设置的值")  设置元素的值。

        错误操作: $("#a").value="new value";

        正确操作: $("#a").val("new value");

    那个错误例子是我第一次使用的时候,想当然的使用方法。当然,那是不对的。

    数组转换成字符串

    <script lanuage="javascript">

    var tt = new Array("abc","cde","ggg");

    alert(tt.toString());

    alert(tt+"");

    alert(tt.join(""));

    </script>

    示例:

    <script type="text/javascript">

    var dict = new Array();

    dict[""] = "ren";

    dict[""] = "kou";

    dict[""] = "shou";

     

    var arr=new Array();

    arr.push("aaaaaaa");

    arr.push("bbbbbb");

    arr.push("cccc");

    arr.push("ddd");

    alert("dict.toString():"+dict.toString()); //输出空串

    alert("dict.join():"+dict.join()); //输出空串

    alert("dict.toString():"+dict[""]); //输出 ren

    alert("arr.toString():"+arr.toString()); //输出 aaaaaaa,bbbbbb,cccc,ddd

    </script>

     

    后端Java

    spring mvc注解报错信息:

    1.

    2012-2-10 17:46:43 org.apache.catalina.core.ApplicationContext log

    严重: StandardWrapper.Throwable

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'musicManageController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ttpod.recommend.service.INonLocalService com.ttpod.recommend.view.manage.MusicManageController.nonLocalService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.ttpod.recommend.service.INonLocalService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)

     

    解决方案:在nonLocalService前面加上:@service ,以便系统在使用到这个service时就注入。

     

    jar文件搜索

    jar 文件搜索:  http://www.jarvana.com/jarvana/

     

    使用Google code + SVN进行多人开发 

     

    mongoDB 应用

    pring Data MongoDB hello world example

     

    读取不同编码的文本文件

     

    修改java web 项目名称

    第一种方法:

    打开工程所在目录,找到一个 .mymetadata的文件,用写字板打开,内容大致如下:

    <?xml version="1.0" encoding="UTF-8"?>

    <project-module

    type="WEB"

    name="action"

    id="myeclipse.1242011546906"

    context-root="/old"

    j2ee-spec="1.4"

    archive="old.war">

    <attributes>

    <attribute name="webrootdir" value="/WebRoot" />

    </attributes>

    </project-module>

    context-root="/old" 为发布后的目录名,改为 context-root="/new" 之后,用eclipse重新发布的目录名就是new了。如果用war的打包方式发布,则将 archive="old.war"> 改为 archive="new.war">

     

    第二种方法更为简单:

    右键点击你的项目,然后选择属性---->然后点击myeclipse-web选项,修改web context-root名称为你要修改的项目名称和前面重命名的名称一致就可以了。

     

    Java从网络读取图片并保存至本地

    package cn.cctv.net;

    import java.io.ByteArrayOutputStream;

    import java.io.File;

    import java.io.FileOutputStream;

    import java.io.InputStream;

    import java.net.HttpURLConnection;

    import java.net.URL;

    public class ImageRequest {

    /**

    * @param args

    */

    public static void main(String[] args) throws Exception {

    //new一个URL对象

    URL url = new URL("http://img.hexun.com/2011-06-21/130726386.jpg");

    //打开链接

    HttpURLConnection conn = (HttpURLConnection)url.openConnection();

    //设置请求方式为"GET"

    conn.setRequestMethod("GET");

    //超时响应时间为5

    conn.setConnectTimeout(5 * 1000);

    //通过输入流获取图片数据

    InputStream inStream = conn.getInputStream();

    //得到图片的二进制数据,以二进制封装得到数据,具有通用性

    byte[] data = readInputStream(inStream);

    //new一个文件对象用来保存图片,默认保存当前工程根目录

    File imageFile = new File("BeautyGirl.jpg");

    //创建输出流

    FileOutputStream outStream = new FileOutputStream(imageFile);

    //写入数据

    outStream.write(data);

    //关闭输出流

    outStream.close();

    }

    public static byte[] readInputStream(InputStream inStream) throws Exception{

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    //创建一个Buffer字符串

    byte[] buffer = new byte[1024];

    //每次读取的字符串长度,如果为-1,代表全部读取完毕

    int len = 0;

    //使用一个输入流从buffer里把数据读取出来

    while( (len=inStream.read(buffer)) != -1 ){

    //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度

    outStream.write(buffer, 0, len);

    }

    //关闭输入流

    inStream.close();

    //outStream里的数据写入内存

    return outStream.toByteArray();

    }

    }

     

    java检查音频文件是否有效

    /**

    * 判断链接是否是mp3文件的链接

    */

    public boolean isMp3Url(String url){

    URLConnection urlCon=null;

    try {

    URL urlObj=new URL(url);

    urlCon= urlObj.openConnection();

    urlCon.connect();

    if(urlCon.getContentType().equals("audio/mpeg")){ //如果不是音频文件

    return true;

    }

    return false;

    } catch (Exception e) {

    e.printStackTrace();

    return false;

    }finally{

    urlCon=null;

    }

    }

     

    测试函数运行时间的工具类

    通常的做法

    public class TestObject {

    /**

    * 一个用来被测试的方法,进行了一个比较耗时的循环

    */

    public static void testMethod(){

    for(int i=0; i<100000000; i++){

     

    }

    }

    /**

    * 一个简单的测试方法执行时间的方法

    */

    public void testTime(){

    long begin = System.currentTimeMillis();//测试起始时间

    testMethod();//测试方法

    long end = System.currentTimeMillis();//测试结束时间

    System.out.println("[use time]:" + (end - begin));//打印使用时间

    }

     

    public static void main(String[] args) {

    TestObject test=new TestObject();

    test.testTime();

    }

    }

     

    使用Java回调函数来实现

    首先定一个回调接口:

    java 代码

    public interface CallBack {

    //执行回调操作的方法

    void execute();

    }

     

    然后再写一个工具类:

    java 代码

    public class Tools {

    /**

    * 测试函数使用时间,通过定义CallBack接口的execute方法

    * @param callBack

    */

    public void testTime(CallBack callBack) {

    long begin = System.currentTimeMillis();//测试起始时间

    callBack.execute();///进行回调操作

    long end = System.currentTimeMillis();//测试结束时间

    System.out.println("[use time]:" + (end - begin));//打印使用时间

    }

     

    public static void main(String[] args) {

    Tools tool = new Tools();

    tool.testTime(new CallBack(){

    //定义execute方法

    public void execute(){

    //这里可以加放一个或多个要测试运行时间的方法

    TestObject.testMethod();

    }

    });

    }

     

    }

     

    java读取字节流

    import java.net.URL;

    import java.net.URLConnection;

    import java.io.BufferedReader;

    import java.io.IOException;

    import java.io.InputStream;

    import java.io.InputStreamReader;

    import java.util.Date;

    import sun.security.krb5.internal.crypto.c;

    public class urlc {

    void display() {

    byte buf[] = new byte[100];

    try {

    // System.out.print("请输入文件的URL地址: ");

    // // 读取用户输入的URL

    // int count = System.in.read(buf);

    //

    // String addr = new String(buf, 0, count);

    // 将用户输入的URL字符串传入URL类对象

    URL url = new URL(url地址);

    // 创建URLConnection对象,用URLopenConnection方法将连接返回给URLConnection的对象

    // 实际上URLopenConnection的返回值就是一个URLConnection

    URLConnection c = url.openConnection();

    // URLConnectionconnect()方法建立连接

    c.connect();

    // 显示该连接的相关信息,这些都是URLConnection的方法

    System.out.println("内容类型: " + c.getContentType());

    System.out.println("内容编码: " + c.getContentEncoding());

    System.out.println("内容长度: " + c.getContentLength());

    System.out.println("创建日期: " + new Date(c.getDate()));

    System.out.println("最后修改日期: " + new Date(c.getLastModified()));

    System.out.println("终止日期: " + new Date(c.getExpiration()));

    StringBuffer txt = new StringBuffer();

    InputStream in = c.getInputStream();

    InputStreamReader inReader = new InputStreamReader(in);

    BufferedReader reader = new BufferedReader(inReader);

    String rdline = "";

    while ((rdline = reader.readLine()) != null) {

    txt.append(rdline + "\n");

    }

    reader.close();

    System.out.println(txt.toString());

    }

    catch (IOException e) {

    System.out.println(e);

    }

    }

    public static void main(String[] args) {

    urlc app = new urlc();

    app.display();

    }

    }

     

    注意在 for 循环中用continue

    for(Node fileTypeNode:nodeList){

    //文件类型:压缩,高质,普通

    String fileType=fileTypeNode.getText();

    Items item=nonLocalDown.new Items();

    if(fileType.indexOf("压缩")!=-1){

    totalType.append("0");

    item.setSize(fileType.substring(fileType.indexOf('[')+1,fileType.length()-1));

    }else if(fileType.indexOf("清晰")!=-1){

    totalType.append("1");

    item.setSize(fileType.substring(fileType.indexOf('[')+1,fileType.length()-1));

    }else if (fileType.indexOf("高音质")!=-1){

    continue;

    // totalType.append("3");

    // item.setSize(fileType.substring(fileType.indexOf('[')+1,fileType.length()-1));

    }else if (fileType.indexOf("保真")!=-1){

    continue;

    // totalType.append("4");

    // item.setSize(fileType.substring(fileType.indexOf('[')+1,fileType.length()-1));

    }

    Node itemNode=fileTypeNode.getParent();

    …………

    item.setFiletype(fileType);

    }

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    2017-2018-1 20155301 20155307 20155339 《信息安全系统设计基础》 实验一 开发环境的熟悉
    《JAVA程序设计》第八周学习总结
    实验二《Java面向对象程序设计》实验报告
    《JAVA程序设计》第七周学习总结
    《JAVA程序设计》结对编程联系_四则运算(第二周:整体性总结)
    《JAVA程序设计》第六周学习总结
    实验一《Java开发环境的熟悉》实验报告
    《JAVA程序设计》结对编程联系_四则运算(第一周:阶段总结)
    《JAVA程序设计》第五周学习总结
    《JAVA程序设计》第四周学习总结
  • 原文地址:https://www.cnblogs.com/luowei010101/p/2406133.html
Copyright © 2011-2022 走看看