[转]30 Minutes Flex Test-Drive for Java Developers

mikel阅读(725)

转自:http://coenraets.org/testdrive/flex4j/index.htm
30 Minutes Flex Test-Drive for Java Developers
By Christophe Coenraets
Last update: September 6th, 2006
Update (1/12/2007): I put together a Tomcat-based Test Drive Server that includes these samples running out-of-the box. Read this post for more info.
The objective of this test-drive is to give you, in a very short amount of time, an understanding of how Flex works and what it can do. This test-drive consists of a series of samples kept as concise as possible (typically between 10 and 50 lines of code) to clearly expose features of interest. The samples focus primarily on using Flex with a Java back-end. The intended audience is Java developers with no prior knowledge of Flex.
A few things to know before you start…
The Flex programming model is made of:
MXML, an XML language used to declaratively lay out the user interface of your application.
ActionScript, an ECMAScript compliant, object-oriented programming model. With some syntactical differences, ActionScript looks and feels similar to Java, and supports the same object-oriented constructs: packages, classes, inheritance, interfaces, strong (but also dynamic) typing etc.
An extensive set of class libraries. The online API documentation is available here in a Javadoc-like format.
The Flex source code (.mxml and .as files) is compiled into Flash bytecode (.swf) that is executed at the client-side by the Flash virtual machine.
There are different ways you can use the Flex compiler (mxmlc):
From the command line
As part of an ant script
Using FlexBuilder: the compilation process is integrated in the IDE
Using the web compiler (available with the Flex Data Services). This is similar to the JSP compilation model: The first time an application is requested it is compiled into bytecode, which is then cached to serve subsequent requests.
You typically don't use the web compiler in a production environment. However, we are using it in this test-drive to minimize the number of components to install on your machine (all you will need to install is a war file).
The Flex product line includes:
The Flex SDK which is free and includes the Flex libraries, the compiler (mxmlc), the Debugger, and the documentation.
Flex Data Services (FDS), an optional set of server-side components deployed in your J2EE application server. FDS includes a Java RPC service (sample 3), publish/subscribe messaging (samples 6 and 7), and data management services (sample 8). FDS is free for a single-CPU deployment (FDS Express), and is licensed per CPU when deployed on multiple CPUs.
FlexBuilder, an optional IDE for Flex development. Built as an Eclipse plug-in, FlexBuilder includes a design view and a code view, code hinting, visual Debugging, etc. FlexBuilder is licensed on a per developer basis.
Optional charting components licensed on a per developer basis.
You can develop and deploy Flex applications entirely for free using the SDK and the IDE of your choice. I will highlight the examples in this test-drive that require the Flex Data Services.
Installing the Test Drive Files
Since we will be using the Flex Data Services, you need a J2EE server, or, at a minimum, a Servlet container.
Download the testdrive war file.
If you use an application server that implements the full J2EE stack (IBM Websphere, BEA Weblogic, JBoss, JRun, etc.), download the version below. It includes the Flex Data Services, the sample applications, and an embedded HSQLDB database to support the samples.
Proceed to license and download
If you use Tomcat 5.5.x, download the version below. It includes the Flex Data Services, the sample applications, an embedded HSQLDB database to support the samples, and JOTM (an open source implementation of the Java Transaction API required by the data management services wich are used in sample 8).
Proceed to license and download
If you use Tomcat 5.0.x, download the version below. It includes the Flex Data Services, the sample applications, an embedded HSQLDB database to support the samples, and JOTM (an open source implementation of the Java Transaction API required by the data management services wich are used in sample 8):
Proceed to license and download
Note: the only difference between the 5.5.x and 5.0.x version is the configuration of JOTM in META-INF\context.xml (the way you configure UserTransaction has changed in Tomcat 5.5).
Deploy testdrive.war in your application server
Access http://localhost:8080/testdrive (change the host name and port number as appropriate).
Sample 1: Accessing data using HTTPService
Run the sample:
Access http://localhost:8080/testdrive/sample1/SampleXML.mxml
Notice that there is a delay the first time you access an application in this test-drive. This is because we are using the web compiler which compiles your application into bytecode the first time it is accessed (similar to the JSP compilation model). Subsequent requests to the same application will be much faster since the application is already compiled. In a production environment, you would typically deploy precompiled applications.
Note: Depending on your configuration, you may need to increase the heap size of your application server's JVM to use the web compiler. This would not be required in a production environement since you typically don't use the web compiler. If you get a java.lang.OutOfMemoryError exception while trying to access a sample for the first time, you must increase your heap size.
Click “Get Data”: The DataGrid is populated with XML data returned by catalog.jsp
Also notice some of the built-in DataGrid features:
Sortable columns (click on a column header)
Moveable columns (click on a column header and, with the mouse button pressed, move the column to a new position)
Code walkthrough:
Open the following files in a code editor:
testdrive/sample1/SampleXML.mxml
testdrive/sample1/catalog.jsp
Using HTTPService, you can send HTTP requests to a server, and consume the response. Although the HTTPService can be used to consume different types of responses, it is typically used to consume XML. You can use the HTTPService with any kind of server-side technology: JSP, Servlet, ASP, Ruby on Rails, PHP, etc. You specify the target service in the url property of HTTPService.
Flex provides sophisticated data binding capabilities. You can bind the value of a property to the value of another property, or to an expression in general. In this example, the dataProvider property of the DataGrid is bound (using the curly braces notation) to the lastResult property of the HTTPService.
HTTPService calls are asynchronous. The result event is triggered on the HTTPService when the data becomes available to the client application. The fault event is triggered if an error occurs at the server-side, or if the network becomes unavailable. (See sample 5, for an example of coding result and fault event handlers).
By default, the XML document retrieved from the server is deserialized into an object graph. This allows you to navigate through the result using the dot notation. You can also get the result as an XML document by specifying resultFormat=”e4x” on the HTTPService. In that case, you can parse the document using E4X (ECMAScript for XML).
More info:
Both HTTP and HTTPS are supported
Instead of using the url property to specify a hardcoded URL, you can specify a logical name in the destination property. You then map this logical name to an actual URL in WEB-INF\flex\proxy-config.xml. In this example, you could replace url=”catalog.jsp” with destination=”catalog” (open WEB-INF\flex\proxy-config.xml to see how the catalog destination is configured). As another example, to get the headlines from the New York Times, specify destination=”news”, and change the DataGrid data binding to: dataProvider=”{srv.lastResult.rss.channel.item}”.
Sample 2: Accessing data using Web Services
Run the sample:
Access http://localhost:8080/testdrive/sample2/SampleWebService.mxml
Click “Get Data”: The DataGrid is populated with data returned by the ProductWS web service hosted on my blog.
Code walkthrough:
Open the following file in a code editor:
testdrive/sample2/SampleWebService.mxml
Access the wsdl file for the web service used in this example:
http://coenraets.org/services/ProductWS?wsdl
Using the WebService tag, you can invoke SOAP-based web services deployed in your application server or on the internet. Objects returned by a web service are automatically deserialized into ActionScript objects. Similarly ActionScript objects passed as arguments to a web service operation are serialized according the wsdl description.
Notice that we also added DataGrid column definitions (using DataGridColumn) in this example.
More Info:
Flex supports both RPC-encoded and document-literal web services
Like HTTPService, WebService calls are asynchronous: You can code result and fault event handlers
Like when using HTTPService, you can use a logical name instead of a hardcoded URL to identify the service, and map the logical name in WEB-INF\flex\proxy-config.xml.
Sample 3: Accessing data using Java RPC
Run the sample:
Access http://localhost:8080/testdrive/sample3/SamplePOJO.mxml
Click “Get Data”: The DataGrid is populated with data returned by the getProducts() method of the ProductService Java class.
Code walkthrough:
Open the following files in a code editor:
sample3\SamplePOJO.mxml
WEB-INF\src\flex\testdrive\store\ProductService.java
WEB-INF\flex\remoting-config.xml
Using RemoteObject, you can directly invoke methods of Java objects deployed in your application server, and consume the return value. The return value can be a value of a primitive data type, an object, a collection of objects, an object graph, etc.
The value of the destination property of RemoteObject is a logical name that is mapped to a fully qualified java class in remoting-config.xml.
Java objects returned by server-side methods are deserialized into either dynamic or typed ActionScript objects. In this example, we don't have an explicit ActionScript version of the Product Java class. Product objects are therefore deserialized into dynamic objects. In sample 5, we work with an explicit Product class in ActionScript.
More info:
Like HTTPService and WebService, RemoteObject calls are asynchronous. You use the result and fault events of the RemoteObject to handle results and errors (see sample 5).
Sample 4: Flex Programming Model 101
Run the sample:
Access http://localhost:8080/testdrive/sample4/MasterDetail.mxml
Click a phone in the list: the details for the selected phone appear in the right panel
Code walkthrough:
Open the following files in a code editor:
sample4\MasterDetail.mxml
sample4\Thumb.mxml
sample4\ProductView.mxml
Like in any other object-oriented programming language, a Flex application is made of a collection of classes. Using Flex, you can create classes using MXML or ActionScript. You typically create view classes in MXML, and Model and Controller classes in ActionScript.
When you create an mxml file, you are actually creating a class. The root node of the mxml document indicates the class you extend. For example, creating a file named MasterDetail.mxml with an root node is equivalent to creating an ActionScript class with the following signature:
public class MasterDetail extends Application {
}
Similarly, creating a file named ProductView.mxml with a root node is similar to creating a class with the following signature:
public class ProductView extends Panel {
}
Once you have defined a class, you can use it programatically or declaratively (as a tag in MXML) without the need for an additional descriptor file. Public properties are automatically available as tag attributes. For example, in MasterDetail.mxml, we define the tag and bind its product attribute to the selected item in the product list.
Also notice the support for CSS style sheets.
Sample 5: Updating Data
Run the sample:
Access http://localhost:8080/testdrive/sample5/SampleUpdate.mxml
Select a phone
Modify some data in the right panel. For example, the price.
Click Update: changes are sent to the back-end and persisted in the database by the ProductService class.
Code walkthrough:
Open the following files in a code editor:
sample5\SampleUpdate.mxml
sample5\ProductForm.mxml
sample5\Product.as
WEB-INF\src\flex\testdrive\store\ProductService.java
WEB-INF\flex\remoting-config.xml
In Product.as we use the [RemoteClass(alias=”flex.testdrive.store.Product”)] annotation to map the ActionScript version of the Product class (Product.as) to the Java version (Product.java). As a result, Product objects returned by the getProducts() method of ProductService are deserialized into instances of the ActionScript Product class. Similarly, the instance of the ActionScript Product class passed as an argument to the update method of the RemoteObject is deserialized into an instance of the java version of the Product class at the server-side.
Sample 6: Publish/Subscribe Messaging (Data Push Use Case)
Run the sample:
In this example, a Java component publishes simulated real time values to a message queue. The Flex client subscribes to that queue and displays the values in real time.
To start the feed component at the server-side: access http://localhost:8080/testdrive/sample6/startfeed.jsp.
(You can stop the feed by accessing http://localhost:8080/testdrive/sample6/stopfeed.jsp)
Open a browser and access http://localhost:8080/testdrive/sample6/FeedClient.mxml
Click the “Subscribe to 'feed' destination” button: Pushed values appear in the text field
Code walkthrough:
Open the following files in a code editor:
sample6\FeedClient.mxml
WEB-INF\src\flex\testdrive\feed\Feed.Java
WEB-INF\flex\messaging-config.xml
Flex supports publish/subscribe messaging through the Flex Message Service (part of the Flex Data Services). The Flex Message Service manages a set of destinations that Flex clients can publish and subsribe to. Flex provides two components, Producer and Consumer, that you use to respectively publish and subscribe to a destination. To subscribe to a destination, you use the subscribe() method of the Consumer class. When a message is published to a destination you subscribed to, the message event is triggered on the Consumer.
In Feed.java, the Flex Java API (MessageBroker, AsyncMessage) is used to publish messages to the Flex destination. The Javadoc documentation for the Java API is available here. Another option to exchange messages bewteen Flex and Java applications is to map Flex destinations to JMS topics, essentially allowing a Flex client to publish and subscribe to JMS topics. In addition to JMS, the Flex Message Service adapter architecture allows you to integrate with any kind of messaging system.
Flex destinations are configured in messaging-config.xml. You can configure a destination to deliver the messages using a real-time protocol or using polling.
Additional resources:
Check out the portfolio viewer sample for a more complete example of data push.
Sample 7: Publish/Subscribe Messaging (Collaboration Use Case)
Run the sample:
Open http://localhost:8080/testdrive/sample7/Chat.mxml in two different browser windows
Type a message in one of the chat clients and click “Send”: the message appears in the two chat clients
Code walkthrough:
Open the following files in a code editor:
sample7\Chat.mxml
WEB-INF\flex\messaging-config.xml
This sample builds on the concepts and APIs introduced in the previous example. To publish a message from a client, you use the send() method of the Producer class.
The messaging and real time infrastructure available in Flex enables collaboration and data push applications to be built in a scalable and reliable manner while preserving the lightweight web deployment model.
Additional resources:
Check out the Google Map collaboration sample.
Sample 8: Data Management Services
Testing persistence:
Open a browser and access http://localhost:8080/testdrive/sample8/SampleDataService.mxml
Click a DataGrid cell, modify the data in that cell, and press Enter
Click the Refresh button in your browser: Notice that the new value appears in the cell indicating that the data has been successfully persisted.
Testing data synchronization across clients:
Open the same application in a second browser window
Resize the two browser windows so that you can see both at the same time on your screen
Modify data in one browser, and press Enter: notice that the update is automatically pushed to the other client
Code walkthrough:
Open the following files in a code editor:
sample8\SampleDataService.mxml
sample8\Product.as
WEB-INF\src\flex\testdrive\store\ProductAssembler.java
WEB-INF\src\flex\testdrive\store\ProductService.java
WEB-INF\flex\data-management-config.xml
In addition to the RPC services described in samples 1, 2, and 3, the Flex Data Management Services provide an innovative and highly productive approach to synchronize data across tiers and between clients. The Flex Data Management Services consist of a client-side API and server-side services:
At the client-side, “managed objects” keep track of changes made to the data, and notify the back-end of these changes. In SampleDataService.mxml, all you have to do is:
Define a DataService pointing to the “product” destination defined in data-management-config.xml
Invoke the DataService's fill() method to populate the “products” array
Bind the DataGrid to the products array
You don't have to keep track of changes made to the data, nor do you have to invoke remote services to notify the back-end of the changes (create, update, delete) made at the client side.
At the server-side, the Data Service receives the list of changes and passes it to your server-side persistence components. The Data Service also pushes the changes to other clients. In this example, the “product” DataService configured in data-management-config.xml uses the java-dao adapter, indicating that we will take care of the persistence code with our own Java classes (another option is to use the Hibernate adapter). There is no specific contract imposed on the Java class that provides the persistence implementation: You map methods such as fill and sync to actual methods in an assembler class (in this case: ProductAssembler). In the assembler class, you typically delegate the actual persistence implementation to existing persistence classes (in this case: ProductService).
Sample 9: Data Visualization
Run the sample :
Access http://localhost:8080/testdrive/sample9/Dashboard.mxml
Click on any data point on the line chart, the column chart at the bottom of the screen is updated to display a product breakdown for the selected month.
Code walkthrough:
Open the following files in a code editor:
sample9\Dashboard.mxml
Flex provides and extensive library of charting components such as LineChart and PieChart used in this example. Other charting components include ColumnChart, BarChart, AreaChart, BubbleChart, CandlestickChart, PlotChart, HLOCChart.
Flex charting components work like the other data aware components: you use the dataProvider property to bind a chart to data.
Because they leverage vector graphics, charting components can be redrawn and animated at the client-side, helping the end-user to better understand data trends and transitions.
Additional resources:
Dashboard sample on adobe.com
Ely Greenfield's Chart Sampler
Interactive bubble chart, another charting component example from Ely
Sample 10: Rich Media
Run the sample:
Access http://localhost:8080/testdrive/sample10/SampleMedia.mxml
Click on a question in the list: a video appears, adding a rich media experience to this traditional “FAQ” application.
Code walkthrough:
Open the following files in a code editor:
sample10\SampleMedia.mxml
sample10\questions.mxml
HTTPService is used to retrieve an XML document that contains the list of questions, video links, and cuepoints.
The source attribute of the VideoDisplay component is bound to the selectedItem in the List, so that the “answer video” automatically starts palying when a question is clicked.
The cuepoint event is used on VideoDisplay to synchronize the captions (the captions are not part of the video, but where read from the XML document).
Also notice how the resizeEffect is used on the Panel component, to animate the panel when it is resized.
Finally the applications has two view states: the default state and the “videoPlaying” state. View states allow you to declaratively (using MXML) represent different states of the applications. In this simple case, the Panel is expanded in the videoPlaying state to reveal the VideoDisplay component.
Appendix A: Data Access and Rendering Performance
To test data retrieval and rendering:
Access http://localhost:8080/testdrive/appendixa/Perf.mxml
Specify a number of rows to retrieve
Click “Get Data”
Watch the number of milliseconds it took to retrieve and render the data
To test client-side sorting:
Specify 20000 rows
Click “Get Data”
Click on a column header to sort 20000 rows at the client-side
Code walkthrough:
Open the following files in a code editor:
sample11\Perf.mxml
WEB-INF\src\flex\testdrive\census\CensusService.java
WEB-INF\flex\remoting-config.xml
At the client-side, we use RemoteObject to remotely invoke the getItems method on the CensusService class deployed in the application server. The CensusService class accesses the embedded HSQLDB database and returns the number of rows requested. Using RemoteObject, the data is transferred in a binary format over HTTP.
Appendix B: Creating Custom UI Components
Run the sample:
Access http://localhost:8080/testdrive/appendixb/Store.mxml
Modify the price range using the slider: filtered items are animated in and out of the list to help the user visualize the products affected by the filter
Code walkthrough:
Open the following files in a code editor:
sample12\Store.mxml
sample12\AnimatedTileList.as
Although many Flex applications are built entirely using the UI components available in the Flex framework, you can create custom UI components by extending classes in the Flex framework. AnimatedTileList.as provides an example of a class that extends Canvas to provide an animated version of the TileList component.
Summary and Next Steps
This test-drive has provided you with a first experience of Flex, primarily focused on Java integration. However, we have just scratched the surface, and there are many other online resources focusing on the different aspects of the product. flex.org is a great place to start to become familiar with these resources. The developer experience is an important aspect of Flex. So also make sure you download FlexBuilder to start building your own Flex projects.
Don't hesitate to send me your questions/comments on this test-drive and any suggestion to improve it. Thanks! christophe at coenraets dot org.

Flex OpenSource

mikel阅读(866)

Adobe的开源网站
Open Source Flex and BlazeDS
Flex 4, codenamed Gumbo, is now beginning active development. The product plan is not yet complete, but a few themes are under consideration:
* Design in Mind: provide a framework meant for continuous collaboration between designer and developer. Probably involves an additional component model that integrates with the existing Halo components.
* Accelerated Development: take application development from concept to reality quickly. Features could include application templates, architectural framework integration, binding improvements.
* Horizontal Platform Improvements: features that benefit all application and user types. Features could include compiler performance, language enhancements, BiDi components, enhanced text.
* Broadening Horizons: expand the range of applications and use-cases that can leverage Flex. Features could include finding a way to make the framework lighter, supporting more deployment runtimes, runtime MXML.

Flex3破解版

mikel阅读(996)

原文地址: http://bbs.5dou.net/viewthread.php?tid=21&page=1&extra=page%3D1
Flex Builder 3.0正式版+破解补丁
Flex Builder 3.0正式版:
http://download.macromedia.com/pub/flex/flex_builder/FB3_win.exe

http://www.adobe.com/cfusion/tdrc/index.cfm?product=flex
AIR1.0 正式版:
http://airdownload.adobe.com/air … obeAIRInstaller.exe
Flex Builder 3.0破解补丁:压缩包下载

[转]java虚拟机jvm关于内存的设置与调优

mikel阅读(760)

java虚拟机jvm关于内存的设置与调优
JVM内存的设置的原理
默认的java虚拟机的大小比较小,在对大数据进行处理时java就会报错:java.lang.OutOfMemoryError。
设置jvm内存的方法,对于单独的.class,可以用下面的方法对Test运行时的jvm内存进行设置。
java -Xms64m -Xmx256m Test
-Xms是设置内存初始化的大小
-Xmx是设置最大能够使用内存的大小(最好不要超过物理内存大小)
在weblogic中,可以在startweblogic.cmd中对每个domain虚拟内存的大小进行设置,默认的设置是在commEnv.cmd里面。
本文引用地址:http://cnpoint.com/framwwork/2006/1109/content_4563.htm
JVM内存的调优
1. Heap设定与垃圾回收
Java Heap分为3个区,Young,Old和Permanent。Young保存刚实例化的对象。当该区被填满时,GC会将对象移到Old区。Permanent区则负责保存反射对象,本文不讨论该区。
JVM的Heap分配可以使用-X参数设定,
-Xms
初始Heap大小
-Xmx
java heap最大值
-Xmn
young generation的heap大小
JVM有2个GC线程。第一个线程负责回收Heap的Young区。第二个线程在Heap不足时,遍历Heap,将Young 区升级为Older区。Older区的大小等于-Xmx减去-Xmn,不能将-Xms的值设的过大,因为第二个线程被迫运行会降低JVM的性能。
为什么一些程序频繁发生GC?有如下原因:
l 程序内调用了System.gc()或Runtime.gc()。
l 一些中间件软件调用自己的GC方法,此时需要设置参数禁止这些GC。
l Java的Heap太小,一般默认的Heap值都很小。
l 频繁实例化对象,Release对象。此时尽量保存并重用对象,例如使用StringBuffer()和String()。
如果你发现每次GC后,Heap的剩余空间会是总空间的50%,这表示你的Heap处于健康状态。许多Server端的Java程序每次GC后最好能有65%的剩余空间。
经验之谈:
1.Server端JVM最好将-Xms和-Xmx设为相同值。为了优化GC,最好让-Xmn值约等于-Xmx的1/3[2]。
2.一个GUI程序最好是每10到20秒间运行一次GC,每次在半秒之内完成[2]。
注意:
1.增加Heap的大小虽然会降低GC的频率,但也增加了每次GC的时间。并且GC运行时,所有的用户线程将暂停,也就是GC期间,Java应用程序不做任何工作。
2.Heap大小并不决定进程的内存使用量。进程的内存使用量要大于-Xmx定义的值,因为Java为其他任务分配内存,例如每个线程的Stack等。
2.Stack的设定
每个线程都有他自己的Stack。
-Xss
每个线程的Stack大小
Stack的大小限制着线程的数量。如果Stack过大就好导致内存溢漏。-Xss参数决定Stack大小,例如-Xss1024K。如果Stack太小,也会导致Stack溢漏。
3.硬件环境
硬件环境也影响GC的效率,例如机器的种类,内存,swap空间,和CPU的数量。
如果你的程序需要频繁创建很多transient对象,会导致JVM频繁GC。这种情况你可以增加机器的内存,来减少Swap空间的使用[2]。
4.4种GC
第一种为单线程GC,也是默认的GC。,该GC适用于单CPU机器。
第二种为Throughput GC,是多线程的GC,适用于多CPU,使用大量线程的程序。第二种GC与第一种GC相似,不同在于GC在收集Young区是多线程的,但在Old区和第一种一样,仍然采用单线程。-XX:+UseParallelGC参数启动该GC。
第三种为Concurrent Low Pause GC,类似于第一种,适用于多CPU,并要求缩短因GC造成程序停滞的时间。这种GC可以在Old区的回收同时,运行应用程序。-XX:+UseConcMarkSweepGC参数启动该GC。
第四种为Incremental Low Pause GC,适用于要求缩短因GC造成程序停滞的时间。这种GC可以在Young区回收的同时,回收一部分Old区对象。-Xincgc参数启动该GC。
4种GC的具体描述参见[3]。
参考文章:
1. JVM Tuning. http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp#garbage-collection
2. Performance tuning Java: Tuning steps
http://h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,1604,00.html
3. Tuning Garbage Collection with the 1.4.2 JavaTM Virtual Machine .
http://java.sun.com/docs/hotspot/gc1.4.2/
原文地址:http://blog.csdn.net/tyrone1979/archive/2006/09/25/1274458.aspx

ASP中字符函数一览

mikel阅读(727)

函数 语法 功能
Len Len(string|varname) 返回字符串内字符的数目,或是存储一变量所需的字节数。
Trim Trim(string) 将字符串前后的空格去掉
Ltrim Ltrim(string) 将字符串前面的空格去掉
Rtrim Rtrim(string) 将字符串后面的空格去掉
函数 语法 功能
Len Len(string|varname) 返回字符串内字符的数目,或是存储一变量所需的字节数。
Trim Trim(string) 将字符串前后的空格去掉
Ltrim Ltrim(string) 将字符串前面的空格去掉
Rtrim Rtrim(string) 将字符串后面的空格去掉
Mid Mid(string,start,length) 从string字符串的start字符开始取得length长度的字符串,如果省略第三个参数表示从start字符开始到字符串结尾的字符串
Left Left(string,length) 从string字符串的左边取得length长度的字符串
Right Right(string,length) 从string字符串的右边取得length长度的字符串
LCase LCase(string) 将string字符串里的所有大写字母转化为小写字母
UCase UCase(string) 将string字符串里的所有大写字母转化为大写字母
StrComp StrComp(string1,string2[,compare]) 返回string1字符串与string2字符串的比较结果,如果两个字符串相同,则返回0,如果小于则返回-1,如果大于则返回1
InStr InStr(string1,string2[, compare]) 返回string1字符串在string2字符串中第一次出现的位置
Split Split(string1,delimiter[, count[, start]]) 将字符串根据delimiter拆分成一维数组,其中delimiter用于标识子字符串界限。如果省略,使用空格(“”)作为分隔符。
count 返回的子字符串数目,-1 指示返回所有子字符串。
start为 1 执行文本比较;如果为 0 或者省略执行二进制比较。
Replace Replace(expression, find, replacewith[, compare[, count[, start]]]) 返回字符串,其中指定数目的某子字符串(find)被替换为另一个子字符串(replacewith)。
1、Len函数示例:
下面的示例利用 Len 函数返回字符串中的字符数目:
Dim MyString
MyString = Len(“VBSCRIPT”) ''MyString 包含 82、Trim、Ltrim、Rtrim函数示例:
下面的示例利用 LTrim, RTrim, 和 Trim 函数分别用来除去字符串开始的空格、尾部空格、 开始和尾部空格:
Dim MyVar
MyVar = LTrim(” vbscript “) ''MyVar 包含 “vbscript “。
MyVar = RTrim(” vbscript “) ''MyVar 包含 ” vbscript”。
MyVar = Trim(” vbscript “) ''MyVar 包含”vbscript”。
3、Mid函数示例:
下面的示例利用 Mid 函数返回字符串中从第四个字符开始的六个字符:
Dim MyVar
MyVar = Mid(“VB脚本is fun!”, 4, 6) ''MyVar 包含 “Script”。
4、Left函数示例:
下面的示例利用Left 函数返回MyString 的左边三个字母:
Dim MyString, LeftString
MyString = “VBSCript”
LeftString = Left(MyString, 3) ''LeftString 包含 “VBS
5、Right函数示例:
下面的示例利用 Right 函数从字符串右边返回指定数目的字符:
Dim AnyString, MyStr
AnyString = “Hello World” ''定义字符串。
MyStr = Right(AnyString, 1) ''返回 “d”。
MyStr = Right(AnyString, 6) '' 返回 ” World”。
MyStr = Right(AnyString, 20) '' 返回 “Hello World”。
6、LCase函数示例:
下面的示例利用 LCase 函数把大写字母转换为小写字母:
Dim MyString
Dim LCaseString
MyString = “VBSCript”
LCaseString = LCase(MyString) '' LCaseString 包含 “vbscript”。
7、 UCase函数示例:
下面的示例利用 UCase 函数返回字符串的大写形式:
Dim MyWord
MyWord = UCase(“Hello World”) '' 返回”HELLO WORLD”。
8、StrComp函数示例:
下面的示例利用 StrComp 函数返回字符串比较的结果。如果第三个参数为 1 执行文本比较;如果第三个参数为 0 或者省略执行二进制比较。
Dim MyStr1, MyStr2, MyComp
MyStr1 = “ABCD”: MyStr2 = “abcd” ''定义变量。
MyComp = StrComp(MyStr1, MyStr2, 1) '' 返回 0。
MyComp = StrComp(MyStr1, MyStr2, 0) '' 返回 -1。
MyComp = StrComp(MyStr2, MyStr1) '' 返回 1。
9、InStr示例:
下面的示例利用 InStr 搜索字符串:
Dim SearchString, SearchChar, MyPos
SearchString =”XXpXXpXXPXXP”???
SearchChar = “P”??
MyPos = Instr(SearchString, SearchChar)???''返回 9.
注意:返回的不是一个字符串在另一个字符串中第一次出现的字符位置,而是字节位置。
10、Split函数示例:
Dim MyString, MyArray, Msg
MyString = “VBScriptXisXfun!”
MyArray = Split(MyString, “x”,-1,1)
'' MyArray(0) contains “VBScript”.
'' MyArray(1) contains “is”.
'' MyArray(2) contains “fun!”.
Response.Write(MyArray(0))
11、Replace函数示例:
Replace(“ABCD”, “BC”, “12”) ''得到A12D

[转]ASP实例中VBScript的数组变量讲解

mikel阅读(848)

ASP实例中VBScript的数组变量讲解一
数组可以存储一系列相同类型的数据.可以使用循环读取数组中的所有值,如for。
标量变量和数组变量。多数情况下,只需为声明的变量赋一个值。只包含一个值的变量被称为标量变量。有时候,将多个相关值赋给一个变量更为方便,因此可以创建包含一系列值的变量,称为数组变量。数组变量和标量变量是以相同的方式声明的,唯一的区别是声明数组变量时变量名后面带有括号( )。
下例声明了一个包含 11 个元素的一维数组:Dim A(10)
虽然括号中显示的数字是 10,但由于在 VBScript 中所有数组都是基于 0 的,所以这个数组实际上包含 11 个元素。在基于 0 的数组中,数组元素的数目总是括号中显示的数目加 1。这种数组被称为固定大小的数组。
在数组中使用索引为数组的每个元素赋值。从 0 到 10,将数据赋给数组的元素,如下所示:
A(0) = 256
A(1) = 324
A(2) = 100 . . .
A(10) = 55
与此类似,使用索引可以检索到所需的数组元素的数据。
例如:SomeVariable = A(8)
数组并不仅限于一维。数组的维数最大可以为 60(尽管大多数人不能理解超过 3 或 4 的维数)。声明多维数组时用逗号分隔括号中每个表示数组大小的数字。在下例中,MyTable 变量是一个有 6 行和 11 列的二维数组:
Dim MyTable(5, 10)
在二维数组中,括号中第一个数字表示行的数目,第二个数字表示列的数目。
也可以声明动态数组,即在运行脚本时大小发生变化的数组。对数组的最初声明使用 Dim 语句或 ReDim 语句。但是对于动态数组,括号中不包含任何数字。
例如:Dim MyArray()
ReDim AnotherArray()
要使用动态数组,必须随后使用 ReDim 确定维数和每一维的大小。在下例中,ReDim 将动态数组的初始大小设置为 25,而后面的 ReDim 语句将数组的大小重新调整为 30,同时使用 Preserve 关键字在重新调整大小时保留数组的内容。
ReDim MyArray(25)
ReDim Preserve MyArray(30)
重新调整动态数组大小的次数是没有任何限制的,将数组的大小调小时,将会丢失被删除元素的数据。
重定义数组的实例
<% dim x() for i=0 to 10 redim x(i) x(i)=i response.write x(i) next %>
ASP实例中VBScript的数组变量讲解二
使用数组时,有三个函数是你必须掌握的。函数UBOUND()返回一个数组的大小。确切地说,它可以返回数组的某一维的大小。这里有这个函数的一些例子:
<% DIM Product(10,33) %>
<%=UBOUND(Product)%>
<%=UBOUND(Product,1)%>
<%=UBOUND(Product,2)%>
在这个例子中,第一个UBOUND()函数返回值是10。在缺省情况下,这个函数返回的是一个函数的第一维的上界。
第二个UBOUND()函数的返回值与第一个相同。它返回的是数组Product的第一维的上界。
警告
虽然数组的某一维的第一个索引值总是0,但其第一维总是用1表示,不要混淆了维数与索引。
最后,第三个UBOUND()函数的返回值是33。这是数组Product的第二维的维数。
当一个数组不是你声明的,但你需要确定这个数组的大小时,函数UBOUND()是有用的。例如,在第23章“使用记录集中”,你将学习如何从一个数据库表中把记录取到数组中。如果你需要知道这项操作所产生的数组的大小,你可以使用函数 UBOUND()。(知道一个数组的大小使你能够遍历和显示它的所有元素。)
VBScript有一个ERASE语句,可以用来操作固定大小的数组和动态数组。通过对一个静态数组使用ERASE语句,你可以清除这个数组。如果该数组是一个字符串数组,ERASE语句把该数组的所有元素重新初始化为空字符串””。如果该数组是一个数值数组,ERASE语句可以把该数组的所有元素重新初始化为0。这里有一些例子:
<% DIM Product(2) Product(1)=”Running shoes” ERASE Product %>
<%=Product(1)%>
当这个脚本执行时,不会输出任何讯息。ERASE语句清除了数组Product的所有数据,不论有多少元素被分配了值。
当对动态数组使用ERASE语句时,它的作用与上述的不同。当你对动态数组使用ERASE语句时,该数组本身会被删除。在你能重新使用这个数组之前,你必须对它重新初始化。如下例所示:
<% DIM Product() REDIM Product(100) Product(1)=”Running Shoes” ERASE Product %>
这个脚本创建了一个名为Product的动态数组。该数组的索引值为1的元素被赋了一个值。然后,用ERASE语句删除了这个数组。如果你在它被删除之后试图访问这个数组的任何一个元素,则将会发生错误。
当你删除了一个数组后,内存就被释放。对一个访问率很高的站点来说,每一字节的内存都很珍贵。因此当你不再需要一个动态数组时,用ERASE语句删除它是个不错的主意。
操作数组的最后一个有用的函数是ISARRAY()。函数ISARRAY()可以用来测试一个变量表达式是否是一个数组。这里有一个例子:
<% DIM Product(10) DIM somevar %>
<%=ISARRAY(Product)%>
<%=ISARRAY(somevar)%>
在这个例子中,第一个ISARRAY()函数返回TRUE,因为Product实际上是一个数组。第二个ISARRAY()函数返回FALSE,因为变量somevar没有被声明为一个数组。
ASP实例中VBScript的数组变量讲解三
数组函数:Array()[ybj86.cn]
Vbscript定义数组
返回包含数组的 Variant。
Array(arglist)
arglist参数是赋给包含在Variant中的数组元素的值的列表(用逗号分隔)。如果没有指定此参数,则将会创建零长度的数组。
说明:用于引用数组元素的表示符,由跟随有括号的变量名组成,括号中包含指示所需元素的索引号。在下面的示例中,第一条语句创建名为 A 的变量。第二条语句将一个数组赋值给变量 A。最后一条语句将包含在第二个数组元素中的值赋值给另一个变量。
Dim A
A = Array(10,20,30)
B = A(2) ' B is now 30。
注意:未作为数组声明的变量仍可以包含数组。虽然包含数组的 Variant 变量与包含 Variant 元素的数组变量有概念上的不同,但访问数组元素的方法是相同的。

ASP中动态数组的定义

mikel阅读(659)

现在需要一数组,但是大小不固定,所以用动态数组。
dim item()
下面的语句会出现:下标越界 的错误,好像item()现在还不是一个数组一样。
redim preserve item(ubound(item)+1)
但是,我确实需要这么做,下标为0的数组元素也需动态添加进去。
用on error ,但是ASP又不支持goto,即:
on error goto errorHandler
在VB里可以如下做:
Private Sub Form_Load()
On Error GoTo errorHandler
ReDim Preserve item(UBound(item) + 1)
item(UBound(item)) = UBound(item)
errorHandler:
ReDim item(0)
item(0) = 0
End Sub
解决方法:
dim item()
sub aa()
’On Error Resume Next的意思是如果发生错误就继续直接执行出错语句下面的那句。一般的,如果出错,VB会报告并停止运行,但有时错误并不严重,不会产生严重影响,你可以在可能出错的语句前面加上这句。但是如果错误很严重,会影响到后续语句,就不要使用这个方法了。
on error resume next
'重定义item数组的下界=当前下界+1
redim preserve item(ubound(item)+1)
’如果定义错误,当然会报错了,因为ubound(item)根本取不到下界,然后定义item为下界为1
if err.number <>0 then
redim preserve item(1)
end if
response.write uBound(item)
end sub
aa

XP下IIS用户访问连接数限制修改

mikel阅读(735)

问题背景:
服务器经常出现下面的情况,该如何解决
——————————————————————————–
无法显示网页
目前访问网站的用户过多。
请尝试执行下列操作:
单击刷新按钮,或稍后重试。
打开 192.168.0.11 主页,然后查找与所需信息相关的链接。
HTTP 错误 403.9 – 禁止访问:连接的用户过多
Internet 信息服务
——————————————————————————–
技术信息(用于支持人员)
背景:
导致此错误的原因是:Web 服务器忙,因通信量过大而无法处理您的请求。
详细信息:
Microsoft 支持
----------------------------------
解决办法:
我们知道Windows 2000专业版或Windows XP专业版操作系统中IIS最多允许10个客户端的连接,在Windows 2000服务器版或Windows 2003服务器版操作系统中不存在这种连接限制问题。
Microsoft 提供了一个管理IIS的小工具MetaEdit,MetaEdit工作在Windows NT4.0、Windows 2000上,我发现它在Windows XP上也能正常工作,另外,MetaEdit只能管理II4.0、IIS5.0或更高版本的IIS。
下面利用这个工具突破Windows XP专业版IIS客户端连接限制:
首先,你需要到下面的地址下载MetaEdit,最新版本是2.2。
http://download.microsoft.com/download/iis50/Utility/5.0/NT45/EN-US/MtaEdt22.exe
(如果是WINXP+SP2,请下载:SP2限制连接数补丁最新版本2.11a并查看文末说明)
然后,执行MtaEdt22.exe按向导提示完成MetaEdit安装。
最后,在MetaEdit中设置客户端连接限制的参数。
安装MetaEdit完毕后,在开始菜单的程序组Administrative Tools下点击MetaEdit 2.2运行,出现一窗口,在窗口的左边将树展开至LM \\ W3SVC,直接在W3SVC文件夹上单击,选择右边列表中Name为MaxConnections的项,双击后,出现对话框。在最后Data的文本框中默认的是10,这就是Windows XP专业版IIS默认设置的最大客户端连接数了,现在你可以改变这个默认值了,我把它改为10000,
注意:在Win2000 上的IIS客户端连接数最大为2000000000

[原创]获得后缀名为swf的通用正则表达式

mikel阅读(1096)

经过对传统过滤url地址的正则表达式
http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
针对目前flash网站普遍采用的flash文件的连接形式如下:
src=”/www/flash/swfssss.swf”
src=”http://www.flash.net/flass/sss.swf”
src=”../sdfs/ssss.swf”
src=”ssdfd/ssfds/ss.swf”
进行正则表达式的修改,使得能够提取出正确的flash文件地址来进行转换保存
最终的正则表达式为:((http:)|[\w/=]|\.)+[\w-]+(/[\w./?%&=]*)*\.swf
说明:
():表示含有的字符集合
|:表示或
[]:表示包含的指定字符
\w:任意ASCII单字字符,也就是[a-zA-Z0-9]
/=:也就是=
\.:也就是“.”
*:自然是通配符了,所有字符
整体含义是:首字符含有“http:”或“a-zA-Z0-9小数点”后面用“/”分隔开的任意长度字符,结尾为.swf的内容全部过滤出来
呼~~~~~,正则表达式真的是很难理解的,不过只要弄清楚规则后还是需要多实践才能总结出来的
今天的任务完成了,明天写出个通用的结构出来,flash收藏家的核心技术难点就算解决了!爽啊!