FOR XML PATH

FOR XML PATH http://www.cnblogs.com/doubleliang/archive/2011/07/06/2098775.html FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作。那么以一个实例为主. 一.FOR XML PATH 简单介绍 那么还是首先来介绍一下FOR XML PATH ,假设现在有一张兴趣爱好表 (hobby) 用来存放兴趣爱好,表结构如下: 接下来我们来看应用FOR XML PATH的查询结果语句如下: SELECT * FROM @hobby FOR XML PATH 结果: <row> <hobbyID>1</hobbyID> <hName>爬山</hName> </row> <row> <hobbyID>2</hobbyID> <hName>游泳</hName> </row> <row> <hobbyID>3</hobbyID> <hName>美食</hName> </row> 由此可见FOR XML PATH 可以将查询结果根据行输出成XML各式! 那么,如何改变XML行节点的名称呢?代码如下: SELECT * FROM @hobby FOR XML PATH('MyHobby') 结果一定也可想而知了吧?没错原来的行节点<row> 变成了我们在PATH后面括号()中,自定义的名称<MyHobby>,结果如下: <MyHobby> <hobbyID>1</hobbyID> <hName>爬山</hName> </MyHobby> <MyHobby> <hobbyID>2</hobbyID> <hName>游泳</hName> </MyHobby> <MyHobby> <hobbyID>3</hobbyID> <hName>美食</hName> </MyHobby> 这个时候细心的朋友一定又会问那么列节点如何改变呢?还记的给列起别名的关键字AS吗?对了就是用它!代码如下: SELECT hobbyID as 'MyCode',hName as 'MyName' FROM @hobby FOR XML PATH('MyHobby') 那么这个时候我们列的节点名称也会编程我们自定义的名称 <MyCode>与<MyName>结果如下: ...

Created 29296-07-29 · Updated 9096-10-09 · 2 min · 270 words · -

How to configure Office applications to run under a specific user account

How to configure Office applications to run under a specific user account This article was previously published under Q288367 SUMMARY We do not recommend or support automation to a Microsoft Office application from an unattended user account. For additional information on why Microsoft does not recommend automation under this context, click the following article number to view the article in the Microsoft Knowledge Base:257757 Considerations for server-side automation of Office If there is no choice but to automate Office from an unattended user account, the following steps can be used to configure the computer to run the Office application as a specific user, giving the application a fixed identity when it is started for Automation. MORE INFORMATION Caution Automation of any Office application from an unattended, non-interactive user account is risky and unstable. A single error in code or configuration can result in a dialog box that can cause the client process to stop responding (hang), that can corrupt data, or that can even crash the calling process (which could bring down your Web server if the client is ASP). Warning Office was not designed, and is not safe, for unattended execution on a server. Developers who use Office in this manner do so at their own risk. Regardless, it may be absolutely required to use Office in this manner. In these cases, special configuration must be done to avoid errors on Office startup. The steps in this article demonstrate how to configure Office to run as a specific user account when it is started for Automation. When you automate under a specific user account, you should be aware of the following problems: Any process that creates an Automation instance of the configured Office application creates the instance under the specific user account, allowing it to run with that user's security credentials. Setting the Distributed Componenet Object Model (DCOM) settings to run as a specific user is global to the system. This setting affects all users and programs that automate the Office application on the system. Terminal Server clients may not be able to use Office appropriately. You should not use this setting and the steps in this article on an application Terminal Server. Component Object Model (COM) creates a unique WinStation for the new instance of the Office application. Any dialog boxes or warnings that may display do not appear on the interactive desktop. If you set the Visible flag for an application, the interactive user will not see that application. For more information about COM and WinStations, see the "References" section. When COM loads a server to run as a specific user account, the registry hive for that user is not loaded. Because the hive is not loaded for that user, the system .DEFAULT hive is used. Because Office has not been run under an account with this hive, you may receive dialog boxes that prompt you for input or the Office CD-ROMs to complete installation. The dialog boxes are not visible on the interactive desktop, so the application appears to stop responding (hang). The dialog boxes may time out and allow the process to continue, but after a noticeable delay in running the program. To work around this situation, install an NT service that runs under the same user account that is set for the DCOM setting. The NT Service Control Manager (SCM) loads the hive for that user when the service starts. Because the changes in DCOM are global, configuring Office in this manner can have negative side effects for other clients on the system that use Office. It is possible that another client application, or Terminal Server clients, will not be able to use the Office application after the settings are made. Consider carefully what impact this has to your server before you make any changes to the DCOM configuration settings. If the problems listed here are too great for your design, or cause other unidentified problems, it is possible to configure Office differently and still allow it to start from an unattended process or service. For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:288366 How To Configure Office Applications to Run Under the Interactive User Account 288368 How To Configure Office Applications for Automation from a COM+/MTS Package Configuring Office as a Specific User To set up an Office Automation server under a specific user account, follow these steps: Log on to the computer as the Administrator and create a new user account that will automate Office. In our example, this account is named OfficeAutomationUser. Create a password for this user account, and select Never expire so that the password does not have to be changed. Add the OfficeAutomationUser account to the Administrators group. Log in to the computer as OfficeAutomationUser and install (or reinstall) Office using a complete install. For system robustness, it is recommended that you copy the contents of the Office CD-ROM to a local drive and install Office from this location. Start the Office application that you intend to automate. This forces the application to register itself. After the application is running, press ALT+F11 to load the Microsoft Visual Basic for Applications (VBA) editor. This forces VBA to initialize itself. Close the applications, including VBA. Click Start, click Run, and then type `<kbd>``DCOMCNFG</kbd>`. Select the application that you want to automate. The application names are listed below:Microsoft Access 97/2002 - Microsoft Access Database Microsoft Access 2003 - Microsoft Office Access Application Microsoft Excel 97/2000/2002/2003 - Microsoft Excel Application Microsoft Word 97 - Microsoft Word Basic Microsoft Word 2000/2002/2003 - Microsoft Word Document Click Properties to open the property dialog box for this application. ...

Created 23236-09-23 · Updated 9096-10-09 · 7 min · 1362 words · -

Java 循环 loop: while, for, foreach

‘java 循环/loop while,for,foreach’ while( 布尔表达式 ) { //循环内容 } do { //代码语句 }while(布尔表达式); JAVA for循环执行顺序 及 i++和++i的区别 1.i与i++的区别是: ++i 是先执行 i=i+1 再使用 i 的值,而 i++ 是先使用 i 的值再执行 i=i+1。 2.但是如果不了解 for 循环的执行顺序则容易出错。 for循环的执行顺序如下: for(sta1;sta2;sta3) { sta4; } 1.进入循环执行sta1;//只是进入的时候执行. 2.执行sta2;//条件为真才执行sta4,不然就跳出for了. 3,执行sta4; 4,执行sta3; 5,再回到第2步开始执行 Java5新特征之foreach语句使用总结 foreach语句是java5的新特征之一,在遍历数组、集合方面,foreach为开发人员提供了极大的方便。 foreach语句是for语句的特殊简化版本,但是foreach语句并不能完全取代for语句,然而,任何的foreach语句都可以改写为for语句版本。 foreach并不是一个关键字,习惯上将这种特殊的for语句格式称之为"foreach"语句。从英文字面意思理解foreach也就是"for 每一个"的意思。实际上也就是这个意思。 foreach的语句格式: for(元素类型t 元素变量x : 遍历对象obj){ 引用了x的java语句; } 下面通过两个例子简单例子看看foreach是如何简化编程的。代码如下: 一、foreach简化数组和集合的遍历 import java.util.Arrays; import java.util.List; import java.util.ArrayList; /** * Created by IntelliJ IDEA. * User: leizhimin * Date: 2007-12-3 * Time: 16:58:24 * Java5新特征之foreach语句使用总结 */ public class TestArray { public static void main(String args[]) { TestArray test = new TestArray(); test.test1(); test.listToArray(); test.testArray3(); } /** * foreach语句输出一维数组 */ public void test1() { //定义并初始化一个数组 int arr[] = {2, 3, 1}; System.out.println("—-1—-排序前的一维数组"); for (int x : arr) { System.out.println(x); //逐个输出数组元素的值 } //对数组排序 Arrays.sort(arr); //利用java新特性for each循环输出数组 System.out.println("—-1—-排序后的一维数组"); for (int x : arr) { System.out.println(x); //逐个输出数组元素的值 } } /** * 集合转换为一维数组 */ public void listToArray() { //创建List并添加元素 List<String> list = new ArrayList<String>(); list.add("1"); list.add("3"); list.add("4"); //利用froeach语句输出集合元素 System.out.println("—-2—-froeach语句输出集合元素"); for (String x : list) { System.out.println(x); } //将ArrayList转换为数组 Object s[] = list.toArray(); //利用froeach语句输出集合元素 System.out.println("—-2—-froeach语句输出集合转换而来的数组元素"); for (Object x : s) { System.out.println(x.toString()); //逐个输出数组元素的值 } } /** * foreach输出二维数组测试 */ public void testArray2() { int arr2[][] = {{4, 3}, {1, 2}}; System.out.println("—-3—-foreach输出二维数组测试"); for (int x[] : arr2) { for (int e : x) { System.out.println(e); //逐个输出数组元素的值 } } } /** * foreach输出三维数组 */ public void testArray3() { int arr[][][] = { {{1, 2}, {3, 4}}, {{5, 6}, {7, 8}} }; System.out.println("—-4—-foreach输出三维数组测试"); for (int[][] a2 : arr) { for (int[] a1 : a2) { for (int x : a1) { System.out.println(x); } } } } } 运行结果: ...

Created 16166-11-16 · Updated 9096-10-09 · 2 min · 389 words · -

Java 强引用, 软引用, 弱引用, 虚引用

Java 强引用, 软引用, 弱引用, 虚引用 强引用 StrongReference 强引用是使用最普遍的引用。如果一个对象具有强引用,那垃圾回收器绝不会回收它。当内存空间不足,Java虚拟机宁愿抛出OutOfMemoryError错误,使程序异常终止,也不会靠随意回收具有强引用的对象来解决内存不足的问题。 Object o=new Object(); // 强引用 如果不使用时,要通过如下方式来弱化引用,如下: o=null; // 帮助垃圾收集器回收此对象 显式地设置o为null,或超出对象的生命周期范围,则gc认为该对象不存在引用,这时就可以回收这个对象。具体什么时候收集这要取决于gc的算法。 在一个方法的内部有一个强引用,这个引用保存在栈中,而真正的引用内容 (Object) 保存在堆中。当这个方法运行完成后就会退出方法栈,则引用内容的引用不存在,这个Object会被回收。 但是如果这个o是全局的变量时,就需要在不用这个对象时赋值为null,因为强引用不会被垃圾回收。 强引用在实际中有非常重要的用处,举个ArrayList的实现源代码: private transient Object[] elementData; public void clear() { modCount++; // Let gc do its work for (int i = 0; i < size; i++) elementData[i] = null; size = 0; } 在ArrayList类中定义了一个私有的变量elementData数组,在调用方法清空数组时可以看到为每个数组内容赋值为null。不同于elementData=null,强引用仍然存在,避免在后续调用 add()等方法添加元素时进行重新的内存分配。使用如clear()方法中释放内存的方法对数组中存放的引用类型特别适用,这样就可以及时释放内存。 软引用 SoftReference 如果内存空间足够,垃圾回收器就不会回收它,如果内存空间不足了,就会回收这些对象的内存。只要垃圾回收器没有回收它,该对象就可以被程序使用。软引用可用来实现内存敏感的高速缓存。 它兼有了StrongReference和WeakReference的好处,既能停留在内存中,又能在内存不足时去处理。 String str=new String("abc"); // 强引用 SoftReference<String> softRef=new SoftReference<String>(str); // 软引用 虚引用 PhantomReference ...

Created 17176-11-17 · Updated 9096-10-09 · 1 min · 143 words · -

hostapd

hostapd 主页: http://w1.fi/hostapd/ hostapd是一个_IEEE 802.11的AP和IEEE 802.1X/WPA/WPA2/EAP/RADIUS验证器_.此页面用于怎么在linux系统下使用它.其他操作系统请参考hostapd主页 就Linux而言,老版本只能使用以下3个包 HostAP madwifi prism54 所有新的基于mac80211的驱动实现AP功能被hostapd’s nl80211 驱动支持 The mac80211 子系统将所有的master模式已经移到用户空间.通过hostapd去处理客户端验证,设置加密密钥,建立密钥转化策略,以及无线公共部分的其他方面. 由此,老的使用iwconfig <wireless interface> mode master的方法已经不能使用了. 用户空间程序像hostapd目前使用netlink (the nl80211 driver)去创建master mode接口实现通信,monitor mode接口实现接收和发送管理框架 获得hostapd Using your distributions hostapd 在编译和安装你的拷贝之前尝试发行版本是很明智的.这将让你以后的干礼轻松,如果你的版本大于0.6.8或更新,你通过简单配置hostapd-minimal.conf文件来进行测试: change wlan0 to your wireless device interface=wlan0 driver=nl80211 ssid=test channel=1 如果上述配置出现以下错误: hostapd $ sudo hostapd ./hostapd-minimal.conf Configuration file: ./hostapd-minimal.conf Line 2: invalid/unknown driver ’nl80211' 1 errors found in configuration file ‘./hostapd-minimal.conf’ 那就意味着你的hostapd不支持nl80211,你将需要按以下操作编译。如果正常,你可以跳转到配置hostapd章节 下载和编译hostpad 使用基于nl80211的hostapd需要你有至少libnl-1.0 pre8或更新的 genl版本,nl80211依赖Generic Netlink. 大多数发行版都自带有这个或者更新的.在fedora或其它开发包和安装包分开发行版编译 _时,你需要libnl-devel 包 ...

Created 1016-12-01 · Updated 9096-10-09 · 4 min · 834 words · -

usermod

usermod # add user to docker group sudo usermod -aG docker $USER 禁止用户登录 usermod -s /sbin/nologin user0 应用举例: 将 newuser2 添加到组 staff 中 usermod -G staff newuser2 修改 newuser 的用户名为 newuser1 usermod -l newuser1 newuser 锁定账号 newuser1 usermod -L newuser1 解除对 newuser1 的锁定 usermod -U newuser1 功能说明: 修改用户帐号。 语法: usermod [-LU][-c <备注>][-d <登入目录>][-e <有效期限>][-f <缓冲天数>][-g <群组>][-G <群组>][-l <帐号名称>][-s <shell>][-u <uid>][用户帐号] 补充说明: usermod可用来修改用户帐号的各项设定。 参数: -a append -c<备注> 修改用户帐号的备注文字。 -d<登入目录> 修改用户登入时的目录。 -e<有效期限> 修改帐号的有效期限。 -f<缓冲天数> 修改在密码过期后多少天即关闭该帐号。 -g<群组> 修改用户所属的群组。 -G<群组> 修改用户所属的附加群组。 -l<帐号名称> 修改用户帐号名称。 -L 锁定用户密码,使密码无效。 -s<shell> 修改用户登入后所使用的shell。 -u<uid> 修改用户ID。 -U 解除密码锁定。 维护记录 时间 修改内容 原因 2026-10-09 修复本地 Hugo 构建的 Raw HTML 警告:代码/配置放入代码块,正文中的尖括号占位符改为行内代码;categories 改为 Linux 正文中的 HTML/XML 片段被当作原始 HTML 丢弃;文件名/URL/标题按规范调整

Created 1016-12-01 · Updated 9096-10-09 · 1 min · 105 words · -

Linux iwconfig, wpa_supplicant 命令行配置无线上网

linux iwconfig wpasupplicant 命令行配置无线上网,wpa_supplicant install wpa supplicant sudo apt-get install wpasupplicant wpagui sudo pacman -S wpa_supplicant generate psk password wpa_passphrase SSID PASSWORD ##write to file wpa_passphrase SSID PASSWORD >> /etc/wpa_supplicant.conf ##connect sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf , 询问有关命令行配置无线网络的问题,受到启发,做了一点尝试,在这里留下帖子做个笔记。。 我的状况: Debian lenny , kernel 2.6.26-686 , opebox+tint2 网卡两块 Broadcom NetXtreme BCM5710 和 Intel Pro/Wireless 2200BG 步骤有三个: 连接到路由器 命令行 iwconfig <A> essid <B> ap <C> rate <D> freq <E> channel <F> key <G> A: 网 卡在计算机上是别的编号,wlan0等等。 例如,wlan0 ...

Created 1016-12-01 · Updated 9096-10-09 · 2 min · 275 words · -

阻塞队列 BlockingQueue

阻塞队列 BlockingQueue 什么是阻塞队列 阻塞队列 (BlockingQueue) 是一个支持两个附加操作的队列。这两个附加的操作是: 在队列为空时,获取元素的线程会等待队列变为非空。当队列满时,存储元素的线程会等待队列可用。阻塞队列常用于生产者和消费者的场景,生产者是往队列里添加元素的线程,消费者是从队列里拿元素的线程。阻塞队列就是生产者存放元素的容器,而消费者也只从容器里拿元素。 方法\处理方式 抛出异常 返回特殊值 一直阻塞 超时退出 插入方法 add(e) offer(e) put(e) offer(e,time,unit) 移除方法 remove() poll() take() poll(time,unit) 检查方法 element() peek() 不可用 不可用 抛出异常: 是指当阻塞队列满时候,再往队列里插入元素,会抛出IllegalStateException(“Queue full”)异常。当队列为空时,从队列里获取元素时会抛出NoSuchElementException异常 。 返回特殊值: 插入方法会返回是否成功,成功则返回true。移除方法,则是从队列里拿出一个元素,如果没有则返回null 一直阻塞: 当阻塞队列满时,如果生产者线程往队列里put元素,队列会一直阻塞生产者线程,直到拿到数据,或者响应中断退出。当队列空时,消费者线程试图从队列里take元素,队列也会阻塞消费者线程,直到队列可用。 超时退出: 当阻塞队列满时,队列会阻塞生产者线程一段时间,如果超过一定的时间,生产者线程就会退出。 Java里的阻塞队列 JDK7 提供了 7 个阻塞队列 ArrayBlockingQueue : 一个由数组结构组成的有界阻塞队列。 LinkedBlockingQueue : 一个由链表结构组成的有界阻塞队列。 PriorityBlockingQueue : 一个支持优先级排序的无界阻塞队列。 DelayQueue: 一个使用优先级队列实现的无界阻塞队列。 SynchronousQueue: 一个不存储元素的阻塞队列。 LinkedTransferQueue: 一个由链表结构组成的无界阻塞队列。 LinkedBlockingDeque: 一个由链表结构组成的双向阻塞队列。 在JDK1.5新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全"传输"数据的问题。通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便利。 认识BlockingQueue 阻塞队列,顾名思义,首先它是一个队列,通过一个共享的队列,可以使得数据由队列的一端输入,从另外一端输出; 常用的队列主要有以下两种: (当然通过不同的实现方式,还可以延伸出很多不同类型的队列,DelayQueue就是其中的一种) 先进先出 (FIFO) : 先插入的队列的元素也最先出队列,类似于排队的功能。从某种程度上来说这种队列也体现了一种公平性。 后进先出 (LIFO) : 后插入队列的元素最先出队列,这种队列优先处理最近发生的事件。 ...

Created 20206-12-20 · Updated 9096-10-09 · 3 min · 467 words · -

JavaEE Web 工程/项目 目录结构

JavaEE Web 工程/项目 目录结构 Maven 标准目录结构 好的目录结构可以使开发人员更容易理解项目,为以后的维护工作也打下良好的基础。Maven2根据业界公认的最佳目录结构,为开发者提供了缺省的标准目录模板。Maven2的标准目录结构如下: src/main/java Application/Library sources src/main/resources Application/Library resources src/main/webapp Web application sources src/test/java Test sources src/test/resources Test resources src/main/filters Resource filter files src/main/assembly Assembly descriptors src/main/config Configuration files src/main/scripts Application/Library scripts src/test/filters Test resource filter files src/site Site LICENSE.txt Project's license NOTICE.txt Notices and attributions required by libraries that the project depends on README.txt Project's readme 使用目录模板,可以使 pom.xml 更简洁。因为 Maven2 已经根据缺省目录,预定义了相关的动作,而无需人工的干预。以 resources 目录为例: ...

Created 1016-01-01 · Updated 9096-10-09 · 1 min · 195 words · -

Tomcat 访问日志

Tomcat 访问日志 http://hooray520.iteye.com/blog/1335156 Tomcat的访问日志是靠org.apache.catalina.valves.AccessLogValve来控制的,你可以修改$tomcat/conf/server.xml来启用它 ($tomcat是Tomcat安装的目录)。AccessLogValve默认应该是注释掉的,简单的将其注释去掉,然后重启Tomcat就可以了。 以下是Tomcat默认的配置: 引用 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> 你可以设置日志保存的目录(directory),日志的文件名的前缀(prefix),后缀(suffix)和日志的具体格式。保存目录,文件名的前缀、后缀都很简单,一般默认设置也就可以了。resolveHost出于性能的考虑,一般也设为false. 但访问日志的格式(pattern)却有很多的选项供你选择。以下列出了一些基本的日志格式项: 引用 %a – 远程主机的IP (Remote IP address) %A – 本机IP (Local IP address) %b – 发送字节数,不包含HTTP头,0字节则显示 ‘-’ (Bytes sent, excluding HTTP headers, or ‘-’ if no bytes were sent) %B – 发送字节数,不包含HTTP头 (Bytes sent, excluding HTTP headers) %h – 远程主机名 (Remote host name) %H – 请求的具体协议,HTTP/1.0 或 HTTP/1.1 (Request protocol) %l – 远程用户名,始终为 ‘-’ (Remote logical username from identd (always returns ‘-’)) %m – 请求方式,GET, POST, PUT (Request method) %p – 本机端口 (Local port) %q – 查询串 (Query string (prepended with a ‘?’ if it exists, otherwise an empty string) %r – HTTP请求中的第一行 (First line of the request) %s – HTTP状态码 (HTTP status code of the response) %S – 用户会话ID (User session ID) %t – 访问日期和时间 (Date and time, in Common Log Format format) %u – 已经验证的远程用户 (Remote user that was authenticated %U – 请求的URL路径 (Requested URL path) %v – 本地服务器名 (Local server name) %D – 处理请求所耗费的毫秒数 (Time taken to process the request, in millis) %T – 处理请求所耗费的秒数 (Time taken to process the request, in seconds) 你可以用以上的任意组合来定制你的访问日志格式,也可以用下面两个别名common和combined来指定常用的日志格式: ...

Created 10106-01-10 · Updated 9096-10-09 · 2 min · 337 words · -

静态 HTML 页面调用其他 HTML 页面内容的几种方法

静态页面html调用静态页面html的内容几种方法 静态页面html调用静态页面html的内容几种方法 简介: 在论坛中常常有网友问到,可以在一个html的文件当中读取另一个html文件的内容吗?答案是确定的,而且方法不只一种,在以前我只会使用iframe来引用,后来发现了另外的几种方法,那今天就总结这几种方法让大家参考一下,本人觉得第三种方式较好! 1.IFrame引入,看看下面的代码 你会看到一个外部引入的文件,但会发现有一个类似外框的东西将其包围,可使用 但你会发现还会有点问题,就是背景色不同,你只要在引入的文件import.htm中使用相同的背景色也可以,但如果你使用的是IE5.5的话,可以看看这篇关于透明色的文章 如果想引入的文件过长时不出现滚动条的话在import.htm中的body中加入scroll=no 2.方式 3.Behavior的download方式 <script> function onDownloadDone(downDate){ showImport.innerHTML=downDate } oDownload.startDownload('import.htm',onDownloadDone) </script> 维护记录 时间 修改内容 原因 2026-10-09 修复本地 Hugo 构建的 Raw HTML 警告:代码/配置放入代码块,正文中的尖括号占位符改为行内代码;文件重命名为 html-include.md;title 改为「静态 HTML 页面调用其他 HTML 页面内容的几种方法」;url 改为 html-include;旧 url 加入 aliases;categories 改为 Web 正文中的 HTML/XML 片段被当作原始 HTML 丢弃;文件名/URL/标题按规范调整

Created 12126-02-12 · Updated 9096-10-09 · 1 min · 46 words · -

JavaScript 加载顺序

Javascript 加载顺序 Javascript加载顺序 http://www.benben.cc/blog/?p=9 最近经常看到别人提及Javascript脚本的加载顺序,看完之后虽略有所悟,但古人云"纸上得来终觉浅,绝知此事要躬行。“这句话云的好,所以我决定亲自测试一下,看看浏览器究竟是怎么加载脚本的。 先看html部分的代码: <script>alert("我是html根节点之外的内部脚本");</script> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js</title> <style type="text/css">body {margin:0;padding:0;}</style> <script>alert("我是头部header里的内部脚本");</script> <script src="header.js"></script> <script src="outer.js"></script> </head> <body> <script>alert("我是页面body里的内部脚本");</script> <script src="body.js"></script> <input type="button" value="绑定事件" onclick="javascript:alert('我是body中的按钮,这是我自己绑定的事件');"></input> </body> </html> <script>alert("我是html根节点之外的内部脚本");</script> 再看header.js中的代码: 1 alert("我是header中src外部引用的脚本"); 接着是outer.js中的代码: document.write('<script type="text/javascript">'); document.write('alert("我是header中通过外部通过document.write生成的脚本")'); //document.write('<script src="outerouter.js"></script>'); document.write('</script>'); 最后是body.js中的代码 1 alert("我是body中src外部引用的脚本"); 代码的输出顺序如下: alert("我是html根节点之外的内部脚本"); alert("我是头部header里的内部脚本"); alert("我是header中src外部引用的脚本"); alert("我是header中通过外部通过document.write生成的脚本"); alert("我是页面body里的内部脚本"); alert("我是body中src外部引用的脚本"); alert("我是html根节点之外的内部脚本"); 最后只有点击按钮才会触发alert(‘我是body中的按钮,这是我自己绑定的事件’); 刚开始看完代码后你觉得加载顺序如何呢?其实很简单,浏览器加载的时候完全是按照自上而下顺序加载的,遇到外部引用就暂时跳出到外部js中执行,执行完毕后返回跳出的位置继续向下执行,而且经测试可以看到,按钮是在body.js执行完毕后才显示在页面中的,这也证实了浏览器是顺序加载的。 这里需要说明两点: 浏览器根节点之外是不允许有任何元素的,在这里我们只是为了判断加载顺序才写了不符合规矩的代码,这一点可以在chrome的调试中看到报错。 outer.js中通过document.write再次引用外部js的那一行我已经做了注释,虽然此方法有许多人证实可行,但是在我的环境下会报脚本错误,而且这样做会引起浏览器加载顺序的不兼容 (详情可见: Javascript加载顺序的BUG) ,因此在实际应用中若非迫不得已还是少用为妙。 维护记录 时间 修改内容 原因 2026-10-09 修复本地 Hugo 构建的 Raw HTML 警告:代码/配置放入代码块,正文中的尖括号占位符改为行内代码;文件重命名为 javascript-load-order.md;title 改为「JavaScript 加载顺序」;url 改为 javascript-load-order;旧 url 加入 aliases 正文中的 HTML/XML 片段被当作原始 HTML 丢弃;文件名/URL/标题按规范调整

Created 21216-02-21 · Updated 9096-10-09 · 1 min · 88 words · -

Javascript 重定向 window.location.href / replace / reload()

Javascript 重定向 window.location.href / replace / reload() location.href,可以点击浏览器的后退按钮返回本页。 location.assign(URL) assign() 方法可加载一个新的文档。效果与location.href相当。 location.reload(force) 如果该方法没有规定参数,或者参数是 false,它就会用 HTTP 头 If-Modified-Since 来检测服务器上的文档是否已改变。如果文档已改变,reload() 会再次下载该文档。如果文档未改变,则该方法将从缓存中装载文档。这与用户单击浏览器的刷新按钮的效果是完全一样的。 如果把该方法的参数设置为 true,那么无论文档的最后修改日期是什么,它都会绕过缓存,从服务器上重新下载该文档。这与用户在单击浏览器的刷新按钮时按住 Shift 健的效果是完全一样。 location.replace(newURL) 不能点击浏览区的后退按钮返回本页。 将地址替换成新url,该方法通过指定URL替换当前缓存在历史里 (客户端) 的项目, 因此当使用replace方法之后,你不能通过"前进"和"后 退"来访问已经被替换的URL,这个特点对于做一些过渡页面非常有用! replace() 方法不会在 History 对象中生成一个新的记录。当使用该方法时,新的 URL 将覆盖 History 对象中的当前记录。 http://jun1986.iteye.com/blog/1176909 一、最外层top跳转页面,适合用于iframe框架集 top.window.location.href("${pageContext.request.contextPath}/Login_goBack"); ============================================================================================ 二、window.location.href和window.location.replace的区别 1.window.location.href=“url”: 改变url地址; 三、强制页面刷新 1.window.location.reload(): 强制刷新页面,从服务器重新请求! ============================================================================================ 四、window.location.reload();页面实现跳转和刷新 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand('Refresh') 6 window.navigate(location) 7 location.replace(location) 8 document.URL=location.href 这几个都可以刷新 window.location.reload();刷新 ...

Created 3036-03-03 · Updated 9096-10-09 · 1 min · 156 words · -

JDBC URL

JDBC URL disable tls JDK8版本过高引起MySQL连接失败:javax.net.ssl.SSLHandshakeException: No appropriate protocol >[https://juejin.cn/post/6969142310718144520](https://juejin.cn/post/6969142310718144520) jdbc:mysql://127.0.0.1/database0?useunicode=true&characterencoding=utf8&tinyInt1isBit=false&useSSL=false MySQL MySQL Connector/J Driver 驱动程序包: http://mvnrepository.com/artifact/MySQL/MySQL-connector-java 驱动程序类名: com.MySQL.jdbc.Driver JDBC URL Format The general format for a JDBC URL for connecting to a MySQL server is as follows, with items in square brackets ([ ]) being optional: jdbc:MySQL://[host1][:port1][,[host2][:port2]]…[/[database]] [?propertyName1=propertyValue1[&propertyName2=propertyValue2]...] Here is a simple example for a connection URL: jdbc:MySQL://localhost:3306/sakila?profileSQL=true JDBC URL: jdbc:MySQL://<host>:<port>/<database_name> 默认端口3306,如果服务器使用默认端口则port可以省略 MySQL Connector/J Driver 允许在URL中添加额外的连接属性jdbc:MySQL://<host>:<port>/<database_name>?property1=value1&property2=value2 常用的有两个,一个是gjt (Giant Java Tree) 组织提供的MySQL驱动,其JDBC Driver名称 (JAVA类名) 为: org.gjt.mm.MySQL.Driver ...

Created 5056-03-05 · Updated 9096-10-09 · 2 min · 350 words · -

JS 正则标志 /g /i /m 的用法

js正则标志/g /i /m的用法 正则的思想都是一样的,但是具体的写法会有所不同,在这里提到的/g,/i,/m在其他的地方也许就不能用了。 一,js正则标志/g,/i,/m说明 1,/g 表示该表达式将用来在输入字符串中查找所有可能的匹配,返回的结果可以是多个。如果不加/g最多只会匹配一个 2,/i 表示匹配的时候不区分大小写 3,/m 表示多行匹配,什么是多行匹配呢?就是匹配换行符两端的潜在匹配。影响正则中的^$符号 二,实例说明 1,/g的用法 查看复制打印? <script type="text/javascript"> str = "tankZHang (231144)"+ "tank ying (155445)"; res = str.match(/tank/); //没有加/g alert(res); //显示一个tank res = str.match(/tank/g); //加了/g alert(res); //显示为tank,tank </script> 2,/i的用法 查看复制打印? <script type="text/javascript"> str = "tankZHang (231144)"+ "tank ying (155445)"; res = str.match(/zhang/); alert(res); //显示为null res = str.match(/zhang/i); //加了/i alert(res); //显示为ZHang </script> 3,/m的用法 查看复制打印? <script type="text/javascript"> var p = /$/mg; var s = '1\n2\n3\n4\n5\n6'; alert(p.test(s)); //显示为true alert(RegExp.rightContext.replace(/\x0A/g, '\\a')); //显示\a2\a3\a4\a5\a6 alert(RegExp.leftContext); //显示为竖的2345 alert(RegExp.rightContext); //显示为6 var p = /$/g; var s = '1\n2\n3\n4\n5\n6'; alert(p.test(s)); //显示为true alert(RegExp.rightContext.replace(/\x0A/g, '\\a')); //什么都不显示 alert(RegExp.leftContext); //显示为竖的123456 alert(RegExp.rightContext); //什么都不显示 var p = /^/mg; var s = '1\n2\n3\n4\n5\n6'; alert(p.test(s)); //显示为true alert(RegExp.rightContext.replace(/\x0A/g, '\\a')); //显示为1\a2\a3\a4\a5\a6 alert(RegExp.leftContext); //显示为竖的12345 alert(RegExp.rightContext); //显示为6 </script> //从上例中可以看出/m影响的^$的分割方式 上面说的三个例子,/i,/g,/m分开来说的,可以排列组合使用的。个人觉得/m没有多大用处 http://blog.51yip.com/jsjquery/1076.html javascript 密码 正则 let testPassword = /^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[!@#$%^&;*()_=+\-])[a-zA-Z\d!@#$%^&;*()_=+\-]*$/; //判断输入格式 if(testPassword.test(this.passwordText)){ ...密码匹配成功 }else { ...密码匹配失败 } ———————————————— 版权声明:本文为CSDN博主「weixin_42553179」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_42553179/article/details/103045970 ...

Created 10106-03-10 · Updated 9096-10-09 · 1 min · 165 words · -

Java 获取客户端真实 IP 地址的两种方法

Java获取客户端真实IP地址的两种方法 http://dpn525.iteye.com/blog/1132318 在JSP里,获取客户端的IP地址的方法是: request.getRemoteAddr () ,这种方法在大部分情况下都是有效的。但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实IP地址了。 在JSP里,获取客户端的IP地址的方法是: request.getRemoteAddr () ,这种方法在大部分情况下都是有效的。但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实IP地址了。 如果使用了反向代理软件,将http://192.168.1.110: 2046/ 的URL反向代理为 http://www.javapeixun.com.cn / 的URL时,用request.getRemoteAddr () 方法获取的IP地址是: 127.0.0.1或192.168.1.110,而并不是客户端的真实IP。 经过代理以后,由于在客户端和服务之间增加了中间层,因此服务器无法直接拿到客户端的IP,服务器端应用也无法直接通过转发请求的地址返回给客户端。但是在转发请求的HTTP头信息中,增加了X-FORWARDED-FOR信息。用以跟踪原有的客户端IP地址和原来客户端请求的服务器地址。当我们访问http://www.javapeixun.com.cn/index.jsp/ 时,其实并不是我们浏览器真正访问到了服务器上的index.jsp文件,而是先由代理服务器去访问http://192.168.1.110: 2046/index.jsp ,代理服务器再将访问到的结果返回给我们的浏览器,因为是代理服务器去访问index.jsp的,所以index.jsp中通过request.getRemoteAddr () 的方法获取的IP实际上是代理服务器的地址,并不是客户端的IP地址。 于是可得出获得客户端真实IP地址的方法一: public String getRemortIP(HttpServletRequest request) { if (request.getHeader("x-forwarded-for") == null) { return request.getRemoteAddr(); } return request.getHeader("x-forwarded-for"); } 可是当我访问http://www.5a520.cn /index.jsp/ 时,返回的IP地址始终是unknown,也并不是如上所示的127.0.0.1或192.168.1.110了,而我访问http://192.168.1.110: 2046/index.jsp 时,则能返回客户端的真实IP地址,写了个方法去验证。原因出在了Squid上。squid.conf 的配制文件forwarded_for 项默认是为on,如果 forwarded_for 设成了 off 则: X-Forwarded-For: unknown 于是可得出获得客户端真实IP地址的方法二: public String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; } 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,究竟哪个才是真正的用户端的真实IP呢? ...

Created 13136-03-13 · Updated 9096-10-09 · 2 min · 340 words · -

favicon

favicon 获取网站favicon http://www.google.com/s2/favicons?domain=google.com home.html 代码如下: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>home page</title> </head> <body> home page </body> </html> 下面两行代码就可以告诉浏览器使用wangyi.ico 作为home.html的图标了: 维护记录 时间 修改内容 原因 2026-10-09 修复本地 Hugo 构建的 Raw HTML 警告:代码/配置放入代码块,正文中的尖括号占位符改为行内代码;文件重命名为 get-favicon.md;url 改为 get-favicon;旧 url 加入 aliases;categories 改为 Web 正文中的 HTML/XML 片段被当作原始 HTML 丢弃;文件名/URL/标题按规范调整

Created 19196-03-19 · Updated 9096-10-09 · 1 min · 44 words · -

Java JSON 类库: Json-lib, Gson, Jackson, FastJson

4款json的java类库, FastJson JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。 易于人阅读和编写。同时也易于机器解析和生成。 它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集。 JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言。 下面介绍四款处理json的java类库: Json-lib、Gson、Jackson、Fastjson FastJson Fastjson是一个Java语言编写的JSON处理器,由阿里巴巴公司开发。网址: https://github.com/alibaba/fastjson maven依赖配置: <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.79</version> </dependency> 示例: public static String bean2Json(Object obj){ return JSON.toJSONString(obj); } VO vo = JSON.parseObject("...", VO.class); Json-lib JSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans. 官网: http://json-lib.sourceforge.net/ ...

Created 31316-03-31 · Updated 9096-10-09 · 5 min · 957 words · -

SAX 解析和生成 XML 文档

SAX解析和生成XML文档 SAX解析和生成XML文档 分类: 【xml】 2013-09-24 22:37 2207人阅读 评论(6) 收藏 举报 生成解析xmljavasax 目录? 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本人声明。否则将追究法律责任。 作者: 永恒の_☆ 地址: http://blog.csdn.net/chenghui0317/article/details/11990891 一、前言 SAX操作xml是基于事件来完成的,自己只负责调用解析的方法,然后具体解析操作都是交给DefaultHandler处理者来完成的,总的来说使用SAX解析和生成xml文档还是比较方便的 。 二、准备条件 因为SAX是jdk自带的解析方式,所以不用添加jar包引用。 三、使用SAX实战 解析xml文档 实现思路: <1>先由SAXParserFactory这个工厂的实例生产一个SAXParser解析器; <2>然后根据读取的xml路径,传递给SAXParser这个解析器,再调用parse()方法; <3>在parse()方法中需要传递DefaultHandler这个类的扩展类的实例,因为它才会真正去一步步去解析xml文档的; <4>在DefaultHandler扩展类中需要重写startDocument(),endDocument()等等方法,因为他们方法内部有返回的具体文档的结果。 具体代码如下: import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Result; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; /** * 使用SAX操作xml的简单例子 * @author Administrator * */ public class SAXOperateXmlDemo { public void parseXml01(){ String xmlPath = "D:\\project\\dynamicWeb\\src\\resource\\user01.xml"; String xmlName = xmlPath.substring(xmlPath.lastIndexOf("\\")); try { //获取SAX分析器的工厂实例,专门负责创建SAXParser分析器 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); //获取SAXParser分析器的实例 SAXParser saxParser = saxParserFactory.newSAXParser(); //和其他解析方式一样,也要间接通过InputStream输入流对象获取xml信息 //1、直接指定绝对路径获取文件输入流对象 //InputStream inputStream = new FileInputStream(xmlPath); //2、使用类的相对路径查找xml路径 //InputStream inputStream = this.getClass().getResourceAsStream(xmlName); //3、也可以指定路径完成InputStream输入流的实例化操作 InputStream inputStream = new FileInputStream(new File(xmlPath)); //4、使用InputSource输入源作为参数也可以转换xml //InputSource inputSource = new InputSource(inputStream); //解析xml文档 saxParser.parse(inputStream, new XmlSAXHandler01());//这里传递了自定义的XmlSAXHandler()管理者参数来解析xml,不像以前都是直接调用返回的Document对象 } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { SAXOperateXmlDemo demo = new SAXOperateXmlDemo(); demo.parseXml01(); } } /** * 解析SAX的处理者01 * @author Administrator * */ class XmlSAXHandler01 extends DefaultHandler { @Override public void startDocument() throws SAXException { System.out.println("-->startDocument() is invoked..."); super.startDocument(); } @Override public void endDocument() throws SAXException { System.out.println("-->endDocument() is invoked..."); super.endDocument(); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { System.out.println("--->startElement() is invoked..."); super.startElement(uri, localName, qName, attributes); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { System.out.println("--->endElement() is invoked..."); super.endElement(uri, localName, qName); } @Override public void characters(char[] ch, int start, int length) throws SAXException { System.out.println("---->characters() is invoked..."); super.characters(ch, start, length); } } 上面代码简单解析了一个xml,user01.xml文件的内容如下: ...

Created 1016-04-01 · Updated 9096-10-09 · 7 min · 1395 words · -

Jackson

Jackson Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json、xml转换成Java对象。 前面有介绍过json-lib这个框架,在线博文: http://www.cnblogs.com/hoojo/archive/2011/04/21/2023805.html 相比json-lib框架,Jackson所依赖的jar包较少,简单易用并且性能也要相对高些。而且Jackson社区相对比较活跃,更新速度也比较快。 一、准备工作 下载依赖库jar包 Jackson的jar all下载地址: http://jackson.codehaus.org/1.7.6/jackson-all-1.7.6.jar 然后在工程中导入这个jar包即可开始工作 官方示例: http://wiki.fasterxml.com/JacksonInFiveMinutes 因为下面的程序是用junit测试用例运行的,所以还得添加junit的jar包。版本是junit-4.2.8 如果你需要转换xml,那么还需要stax2-api.jar 测试类基本代码如下 package com.hoo.test; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.codehaus.jackson.JsonEncoding; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.node.JsonNodeFactory; import org.codehaus.jackson.xml.XmlMapper; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.hoo.entity.AccountBean; /** function:Jackson 将java对象转换成JSON字符串,也可以将JSON字符串转换成java对象 jar-lib-version: jackson-all-1.6.2 jettison-1.0.1 @author hoojo @createDate 2010-11-23 下午04:54:53 ...

Created 4046-04-04 · Updated 9096-10-09 · 9 min · 1878 words · -