Flash 与后台交互方式包括了:
1. LoadVars(xml) 实际上就是flash里面一个对象,类似一个连接器。新建之后,通过sendAndLoad获取、设置值。和httpposter一样
var data_lv = new LoadVars();
2. flash remoting. flash需要安装components;后台服务器需要OpenAMF。
gateway_conn = NetServices.createGatewayConnection(); myService = gateway_conn.getService("myservice", this);
3. webservice 也是在flash里面初始化一个ws的对象,然后调用。var ws:WebService = new WebService(ws_url);
4. XMLSocket 主要是即时通讯 var socket:XMLSocket = new XMLSocket();
5. 直接开flash的socket
http://androider.javaeye.com/blog/268933
在一个AMF交互的例子中,服务器建立一个MAP对象,例如:
HashMap map=new HashMap();
map.put("Event", "人物移动");
map.put("user", "闪刀浪子");
map.put("x", 100);
map.put("y", 100);
这样flash就可以获取这个对象:var obj:Object=new Object();
posted @
2010-06-17 14:15 张辰 阅读(413) |
评论 (2) |
编辑 收藏
1. Spring IoC容器的意义
使用BeanFactory,根据制定的xml, 动态生成对象然后加载。
只要是从BeanFactory获取的对象,都会根据xml进行装配。
2. Spring MVC
在web.xml配置了DispatcherServlet,让所有请求都被这个servlet拦截。同时配置了这个servlet的初始化对象。
。init-param = /WEB-INF/Config.xml ->
。viewResolver::org.springframework.web.servlet.view.InternalResourceViewResolver
。urlMapping::org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
这个urlMapping的目标,可能是被spring接管的对象,例如SimpleFormController
当配置了DispactcherServlet之后,通过设置合适的初始化对象,能够实现某种MVC模式。
3. spring + blazeds 集成
http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/ch02s02.html
在web.xml配置了2个dispatcherservlet
。*.service === /WEB-INF/remoting-servlet.xml
。/messagebroker/* === /WEB-INF/flex-config.xml 表示把blazeds的请求映射到messagebroker
。第一个servlet继续配置了urlMapping
==HessianServiceExporter可将一个普通bean导出成远程服务 这样这些被映射出来的service可以通过url访问。
问题:这些service有固定的方法,比如execute,那么这些方法如何被调用了?代码上看,是被command调用了。
回答:见第二个配置
。第二个servlet同样配置了urlMapping;还包括
..MessageBrokerHandlerAdapter
..RemotingDestinationExporter -> callDisptacherService -> CallDispatcher -> Command.execute
问题:那么CallDispatcher的Call是如何调用的?
回答:在Flash的xml文件里面指定调用了。
这样故事就全部被串起来了。
首先blazeds是个servlet,被封装过后,能够解析flash传输的amf格式。
通过spring的配置,flash的请求被转移到了messagebroker = blazeds,同时这个messagebroker依赖了特定的bean,例如callHandler. 这些handler又依赖了service 的属性,这个属性就是我可以控制的,同时被flash调用的。
例如
what is web.xml :: listener
它能捕捉到服务器的启动和停止! 在启动和停止触发里面的方法做相应的操作!
一定是httpServlet
http://zhidao.baidu.com/question/39980900
如何加载services-config.xml
MessageBrokerFactoryBean将会去寻找BlazeDS的配置文件(默认位置为/WEB-INF/flex/services-config.xml)
posted @
2010-06-17 09:33 张辰 阅读(442) |
评论 (2) |
编辑 收藏
本文讲解一个不规范的spring quick start.
1. 下载spring的插件包,什么版本之类的不用管了。反正能用。
spring.jar
http://www.boxcn.net/shared/yg306zac1h
common-logging.jar
http://www.boxcn.net/shared/ix93ziqljv
2. 进入eclipse,File - New - Java Project.
projectname = spring001 ===> Next
在新建导向的第二页,是Java Settings, 选择Libraries -> Add External JARS -> 添加上面2个jar
finish
3. 进入Package Explorer, 在src下新建一个class.
Package = com.java114.spring.test
Name = HelloWordSpring
再复选框:public static void main(String[] args) 钩上
4. 在HelloWordSpring.java 输入以下的代码
package com.java114.spring.test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class HelloWordSpring
{
private String msg;
public void setMsg(String msg)
{
this.msg = msg;
}
public void sayHello()
{
System.out.println(msg);
}
public static void main(String[] args)
{
Resource res = new ClassPathResource("com/java114/spring/test/bean.xml");
BeanFactory factory = new XmlBeanFactory(res);
HelloWordSpring hello = (HelloWordSpring) factory.getBean("helloBean");
hello.sayHello();
}
}
5. 在和HelloWordSpring.java 相同目录下面,再新建一个xml文件,名字是bean.xml, 内容如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="helloBean" class="com.java114.spring.test.HelloWordSpring">
<property name="msg" value="simple spring demo"/>
</bean>
</beans>
为什么这样写,我也不知道,不管他。
6. 鼠标右键选择HelloWordSpring.java, 选择Run As - Java Applications, 得到结果:
2010-6-16 21:39:47 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [com/java114/spring/test/bean.xml]
simple spring demo
posted @
2010-06-16 20:13 张辰 阅读(244) |
评论 (0) |
编辑 收藏
比较难的一部分
前提条件:
axis安装路径 C:\ericsson\javaextend\axis-1_4
项目名称:axisdemo
已经有的类:com.service.myService.java
配置文件:server-config.wsdd
1. 在项目添加java2wsdl目录
2.目录下面添加build.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project name="Generate WSDL from JavaBeans as Web Services" default="j2w-all" basedir=".">
<property name="build.dir" value="../build/classes" />
<property name="axis.dir" location="C:\ericsson\javaextend\axis-1_4" />
<path id="classpath.id">
<fileset dir="${axis.dir}/lib">
<include name="*.jar" />
</fileset>
<pathelement location="${build.dir}" />
</path>
<taskdef name="axis-java2wsdl" classname="org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask" loaderref="axis">
<classpath refid="classpath.id" />
</taskdef>
<target name="j2w-all">
<antcall target="j2w-JavaBeanWS" />
</target>
<target name="j2w-JavaBeanWS">
<axis-java2wsdl classname="com.service.myService" classpath="${build.dir}" methods="getusername" output="myService.wsdl" location="http://localhost:8080/axisdemo/services/myService" namespace="http://localhost:8080/axisdemo/services/myService" namespaceImpl="http://localhost:8080/axisdemo/services/myService">
</axis-java2wsdl>
</target>
</project>
注意:build.dir / axis.dir / j2w-javabeanws几个地方的内容要修改。
3. 右键点击build.xml,运行ant,就可以看到生成了myService.wsdl
4.现在要把这个wsdl转化成为java,新建目录:wsdl2java
5. 新建一个build.xml,内容:
<?xml version="1.0" encoding="UTF-8"?>
<project name="wsclient" default="all" basedir=".">
<property name="axis.home" location="C:\ericsson\javaextend\axis-1_4" />
<property name="options.output" location="../wsdl2java" />
<path id="axis.classpath">
<fileset dir="${axis.home}/lib">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
<target name="-WSDL2Axis" depends="init">
<mkdir dir="${options.output}" />
<axis-wsdl2java output="${options.output}" url="${options.WSDL-URI}" verbose="true" />
</target>
<target name="init">
<echo>Warning: please update the associated WSDL file(s) in the folder wsdl before running the target!</echo>
<echo>Warning: Just run the target(s) related with your developing work!</echo>
<echo>
</echo>
</target>
<target name="all">
<antcall target="myService" />
</target>
<target name="myService">
<antcall target="-WSDL2Axis">
<param name="options.WSDL-URI" location="../java2wsdl/myService.wsdl" />
</antcall>
</target>
</project>
注意修改的地方:axis.home
6.build ant,在wsdl2java目录下面多出来了4个类:
myService.java
MyServiceService.java
myServiceServiceLocator.java
MyServiceSoapBindingStub.java
全部拷贝到src目录下面
7.在src目录下面添加类:
package com.axistest;
import localhost.axisdemo.services.myService.MyService;
import localhost.axisdemo.services.myService.MyServiceServiceLocator;
public class myServiceTestorByStubs
{
public static void main(String[] args) throws Exception
{
MyServiceServiceLocator Service = new MyServiceServiceLocator();
MyService port = Service.getmyService();
String response port.getusername(邹萍");
System.out.println(response);
}
}
8.最后运行java application就完成了
posted @
2008-12-18 11:03 张辰 阅读(376) |
评论 (0) |
编辑 收藏
reference:
part1
1. in package explorer, change myService.java:
package com.service;
public class myService {
public String getusername(String name){
return "Hello "+name+",this is an Axis Web Service";
}
}
and ctrl+1 to solve the package problem( or you can create dir and move file yourself)
2.in WebContent/WEB-INF/, create server-config.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>
<service name="myService" provider="java:RPC">
<parameter name="className" value="com.service.myService"/>
<parameter name="allowedMethods" value="getusername"/>
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper"/>
</requestFlow>
</transport>
</deployment>
3. in src/, create
myServiceTestorByWSDD.java
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class myServiceTestorByWSDD {
public tatic void main(String[] args) throws ServiceException,MalformedURLException, RemoteException {
String endpoint = http://localhost:8080/oopsaxis1/services/myService;
Service service = new Service(); // 创建一个Service实例,注意是必须的!
Call call = (Call) service.createCall(); // 创建Call实例,也是必须的!
call.setTargetEndpointAddress(new java.net.URL(endpoint));// 为Call设置服务的位置
call.setOperationName("getusername"); // 注意方法名与JavaBeanWS.java中一样!!
String res = (String) call.invoke(new Object[] { "pixysoft" }); // 返回String,传入参数
System.out.println(res);
}
}
4. open tomcat, and :
http://localhost:8080/oopsaxis1/servlet/AxisServlet,you can see:
And now Some Services
myService (wsdl)
getusername
5. right click myServiceTestorByWSDD.java, run as java application.
done!
posted @
2008-12-17 13:51 张辰 阅读(256) |
评论 (0) |
编辑 收藏
reference:
http://www.cnblogs.com/cy163/archive/2008/11/28/1343516.html
pre-condition:
1.install eclipse
2.install tomcat plugin
process:
1.download axis lib: http://ws.apache.org/axis
2. set classpath:
1.AXIS_HOME
D:\Java\axis-1_4(这是我的Axis路径)
2.AXIS_LIB
%AXIS_HOME%\lib
3.AXIS_CLASSPATH
%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar;%AXIS_LIB%\wsdl4j-1.5.1.jar;%AXIS_LIB%\activation.jar;%AXIS_LIB%\xmlrpc-2.0.jar
4.CLASSPATH
.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar; %AXIS_CLASSPATH%;
5.在你的%TOMCAT_HOME%\common\lib下需要加入三个包 activation.jar、mail.jar、tools.jar,注意这三个包是必须的,尽管tools.jar很常见,但这也是运行Axis所必须的包。
3.FIle - new - dynamic web project
projectname: oopsaxis1
target runtime: apache tomcat V5.5
4. oopsaxis1/WebContent/WEB-INF/lib,add lib from %AXIS_HOME%\lib
axis.jar/axis-ant.jar/commons-log.jar...
5.oopsaxis1/WebContent/WEB-INF/web.xml, replace by %AXIS_HOME%\webapps\axis\WEB-INF\web.xml
6.oopsaxis1/src, add java file:
public class myService
{
public String getusername(String name)
{
return "Hello " + name + ",this is an Axis DII Web Service";
}
}
7.copy myService to oopsaxis1/WebContent, and rename to myService.jws
8. right click myService.jws, run as - run on server, you can see:
http://localhost:8080/oopsaxis1/myService.jws
There is a Web Service here
Click to see the WSDL
click the link, you can see the wsdl
9. in eclipse - package explorer - src, new class:
package com.oopsaxis;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class myServiceTestorByjws
{
public static void main(String[] args) throws ServiceException,
MalformedURLException, RemoteException
{
String endpoint = http://localhost:8080/oopsaxis1/myService.jws;
String name = " pixysoft";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.addParameter("param1", XMLType.XSD_STRING, ParameterMode.IN);
call.setOperationName("getusername");
call.setReturnType(XMLType.XSD_STRING);
String ret = (String) call.invoke(new Object[] { name });
System.out.println("返回结果:" + ret);
}
}
10. right click myServiceTestorByjws, run as java application,you get:
返回结果:Hello pixysoft,this is an Axis DII Web Service
done!
posted @
2008-12-17 13:40 张辰 阅读(259) |
评论 (0) |
编辑 收藏
Using Ant
Ant's buildfiles are written in XML. Each buildfile contains one project and at least one (default) target. Targets contain task elements. Each task element of the buildfile can have an id
attribute and can later be referred to by the value supplied to this. The value has to be unique. (For additional information, see the Tasks section below.)
A project has three attributes:
Attribute |
Description |
Required |
name |
the name of the project. |
No |
default |
the default target to use when no target is supplied. |
No; however, since Ant 1.6.0, every project includes an implicit target that contains any and all top-level tasks and/or types. This target will always be executed as part of the project's initialization, even when Ant is run with the -projecthelp option. |
basedir |
the base directory from which all path calculations are done. This attribute might be overridden by setting the "basedir" property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the buildfile will be used. |
No |
Optionally, a description for the project can be provided as a top-level <description>
element (see the description type).
Each project defines one or more targets. A target is a set of tasks you want to be executed. When starting Ant, you can select which target(s) you want to have executed. When no target is given, the project's default is used.
A target can depend on other targets. You might have a target for compiling, for example, and a target for creating a distributable. You can only build a distributable when you have compiled first, so the distribute target depends on the compile target. Ant resolves these dependencies.
It should be noted, however, that Ant's depends
attribute only specifies the order in which targets should be executed - it does not affect whether the target that specifies the dependency(s) gets executed if the dependent target(s) did not (need to) run.
Ant tries to execute the targets in the depends
attribute in the order they appear (from left to right). Keep in mind that it is possible that a target can get executed earlier when an earlier target depends on it:
<target name="A"/>
<target name="B" depends="A"/>
<target name="C" depends="B"/>
<target name="D" depends="C,B,A"/>
Suppose we want to execute target D. From its depends
attribute, you might think that first target C, then B and then A is executed. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.
In a chain of dependencies stretching back from a given target such as D above, each target gets executed only once, even when more than one target depends on it. Thus, executing the D target will first result in C being called, which in turn will first call B, which in turn will first call A. After A, then B, then C have executed, execution returns to the dependency list of D, which will not call B and A, since they were already called in process of dependency resolution for C and B respectively as dependencies of D. Had no such dependencies been discovered in processing C and B, B and A would have been executed after C in processing D's dependency list.
A target also has the ability to perform its execution if (or unless) a property has been set. This allows, for example, better control on the building process depending on the state of the system (java version, OS, command-line property defines, etc.). To make a target sense this property, you should add the if
(or unless
) attribute with the name of the property that the target should react to. Note: Ant will only check whether the property has been set, the value doesn't matter. A property set to the empty string is still an existing property. For example:
<target name="build-module-A" if="module-A-present"/>
<target name="build-own-fake-module-A" unless="module-A-present"/>
In the first example, if the module-A-present
property is set (to any value, e.g. false), the target will be run. In the second example, if the module-A-present
property is set (again, to any value), the target will not be run.
Only one propertyname can be specified in the if/unless clause. If you want to check multiple conditions, you can use a dependend target for computing the result for the check:
<target name="myTarget" depends="myTarget.check" if="myTarget.run">
<echo>Files foo.txt and bar.txt are present.</echo>
</target>
<target name="myTarget.check">
<condition property="myTarget.run">
<and>
<available file="foo.txt"/>
<available file="bar.txt"/>
</and>
</condition>
</target>
If no if
and no unless
attribute is present, the target will always be executed.
Important: the if
and unless
attributes only enable or disable the target to which they are attached. They do not control whether or not targets that a conditional target depends upon get executed. In fact, they do not even get evaluated until the target is about to be executed, and all its predecessors have already run.
The optional description
attribute can be used to provide a one-line description of this target, which is printed by the -projecthelp
command-line option. Targets without such a description are deemed internal and will not be listed, unless either the -verbose
or -debug
option is used.
It is a good practice to place your tstamp tasks in a so-called initialization target, on which all other targets depend. Make sure that target is always the first one in the depends list of the other targets. In this manual, most initialization targets have the name "init"
.
If the depends attribute and the if/unless attribute are set, the depends attribute is executed first.
A target has the following attributes:
Attribute |
Description |
Required |
name |
the name of the target. |
Yes |
depends |
a comma-separated list of names of targets on which this target depends. |
No |
if |
the name of the property that must be set in order for this target to execute. |
No |
unless |
the name of the property that must not be set in order for this target to execute. |
No |
description |
a short description of this target's function. |
No |
A target name can be any alphanumeric string valid in the encoding of the XML file. The empty string "" is in this set, as is comma "," and space " ". Please avoid using these, as they will not be supported in future Ant versions because of all the confusion they cause. IDE support of unusual target names, or any target name containing spaces, varies with the IDE.
Targets beginning with a hyphen such as "-restart"
are valid, and can be used to name targets that should not be called directly from the command line.
A task is a piece of code that can be executed.
A task can have multiple attributes (or arguments, if you prefer). The value of an attribute might contain references to a property. These references will be resolved before the task is executed.
Tasks have a common structure:
<name attribute1="value1" attribute2="value2" ... />
where name is the name of the task, attributeN is the attribute name, and valueN is the value for this attribute.
There is a set of built-in tasks, along with a number of optional tasks, but it is also very easy to write your own.
All tasks share a task name attribute. The value of this attribute will be used in the logging messages generated by Ant.
Tasks can be assigned an
id
attribute:
<taskname id="taskID" ... />
where
taskname is the name of the task, and
taskID is a unique identifier for this task. You can refer to the corresponding task object in scripts or other tasks via this name. For example, in scripts you could do:
<script ... >
task1.setFoo("bar");
</script>
to set the
foo
attribute of this particular task instance. In another task (written in Java), you can access the instance via
project.getReference("task1")
.
Note1: If "task1" has not been run yet, then it has not been configured (ie., no attributes have been set), and if it is going to be configured later, anything you've done to the instance may be overwritten.
Note2: Future versions of Ant will most likely not be backward-compatible with this behaviour, since there will likely be no task instances at all, only proxies.
A project can have a set of properties. These might be set in the buildfile by the property task, or might be set outside Ant. A property has a name and a value; the name is case-sensitive. Properties may be used in the value of task attributes. This is done by placing the property name between "${
" and "}
" in the attribute value. For example, if there is a "builddir" property with the value "build", then this could be used in an attribute like this: ${builddir}/classes
. This is resolved at run-time as build/classes
.
In the event you should need to include this construct literally (i.e. without property substitutions), simply "escape" the '$' character by doubling it. To continue the previous example:
<echo>$${builddir}=${builddir}</echo>
will echo this message:
${builddir}=build/classes
In order to maintain backward compatibility with older Ant releases, a single '$' character encountered apart from a property-like construct (including a matched pair of french braces) will be interpreted literally; that is, as '$'. The "correct" way to specify this literal character, however, is by using the escaping mechanism unconditionally, so that "$$" is obtained by specifying "$$$$". Mixing the two approaches yields unpredictable results, as "$$$" results in "$$".
Ant provides access to all system properties as if they had been defined using a <property>
task. For example, ${os.name}
expands to the name of the operating system.
For a list of system properties see the Javadoc of System.getProperties.
In addition, Ant has some built-in properties:
basedir the absolute path of the project's basedir (as set
with the basedir attribute of <project>).
ant.file the absolute path of the buildfile.
ant.version the version of Ant
ant.project.name the name of the project that is currently executing;
it is set in the name attribute of <project>.
ant.java.version the JVM version Ant detected; currently it can hold
the values "1.2", "1.3", "1.4" and "1.5".
There is also another property, but this is set by the launcher script and therefore maybe not set inside IDEs:
ant.home home directory of Ant
Example Buildfile
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
Notice that we are declaring properties outside any target. As of Ant 1.6 all tasks can be declared outside targets (earlier version only allowed <property>,<typedef> and <taskdef>). When you do this they are evaluated before any targets are executed. Some tasks will generate build failures if they are used outside of targets as they may cause infinite loops otherwise (<antcall>
for example).
We have given some targets descriptions; this causes the projecthelp invocation option to list them as public targets with the descriptions; the other target is internal and not listed.
Finally, for this target to work the source in the src subdirectory should be stored in a directory tree which matches the package names. Check the <javac> task for details.
Token Filters
A project can have a set of tokens that might be automatically expanded if found when a file is copied, when the filtering-copy behavior is selected in the tasks that support this. These might be set in the buildfile by the filter task.
Since this can potentially be a very harmful behavior, the tokens in the files must be of the form @
token@
, where token is the token name that is set in the <filter>
task. This token syntax matches the syntax of other build systems that perform such filtering and remains sufficiently orthogonal to most programming and scripting languages, as well as with documentation systems.
Note: If a token with the format @
token@
is found in a file, but no filter is associated with that token, no changes take place; therefore, no escaping method is available - but as long as you choose appropriate names for your tokens, this should not cause problems.
Warning: If you copy binary files with filtering turned on, you can corrupt the files. This feature should be used with text files only.
You can specify PATH
- and CLASSPATH
-type references using both ":
" and ";
" as separator characters. Ant will convert the separator to the correct character of the current operating system.
Wherever path-like values need to be specified, a nested element can be used. This takes the general form of:
<classpath>
<pathelement path="${classpath}"/>
<pathelement location="lib/helper.jar"/>
</classpath>
The location
attribute specifies a single file or directory relative to the project's base directory (or an absolute filename), while the path
attribute accepts colon- or semicolon-separated lists of locations. The path
attribute is intended to be used with predefined paths - in any other case, multiple elements with location
attributes should be preferred.
As a shortcut, the <classpath>
tag supports path
and location
attributes of its own, so:
<classpath>
<pathelement path="${classpath}"/>
</classpath>
can be abbreviated to:
<classpath path="${classpath}"/>
In addition, one or more Resource Collections can be specified as nested elements (these must consist of file-type resources only). Additionally, it should be noted that although resource collections are processed in the order encountered, certain resource collection types such as fileset, dirset and files are undefined in terms of order.
<classpath>
<pathelement path="${classpath}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
<dirset dir="${build.dir}">
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<filelist refid="third-party_jars"/>
</classpath>
This builds a path that holds the value of ${classpath}
, followed by all jar files in the lib
directory, the classes
directory, all directories named classes
under the apps
subdirectory of ${build.dir}
, except those that have the text Test
in their name, and the files specified in the referenced FileList.
If you want to use the same path-like structure for several tasks, you can define them with a <path>
element at the same level as targets, and reference them via their id attribute--see References for an example.
A path-like structure can include a reference to another path-like structure (a path being itself a resource collection) via nested <path>
elements:
<path id="base.path">
<pathelement path="${classpath}"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
</path>
<path id="tests.path">
<path refid="base.path"/>
<pathelement location="testclasses"/>
</path>
The shortcuts previously mentioned for
<classpath>
are also valid for
<path>
.For example:
<path id="base.path">
<pathelement path="${classpath}"/>
</path>
can be written as:
<path id="base.path" path="${classpath}"/>
In Ant 1.6 a shortcut for converting paths to OS specific strings in properties has been added. One can use the expression ${toString:pathreference} to convert a path element reference to a string that can be used for a path argument. For example:
<path id="lib.path.ref">
<fileset dir="lib" includes="*.jar"/>
</path>
<javac srcdir="src" destdir="classes">
<compilerarg arg="-Xbootstrap/p:${toString:lib.path.ref}"/>
</javac>
Several tasks take arguments that will be passed to another process on the command line. To make it easier to specify arguments that contain space characters, nested arg
elements can be used.
Attribute |
Description |
Required |
value |
a single command-line argument; can contain space characters. |
Exactly one of these. |
file |
The name of a file as a single command-line argument; will be replaced with the absolute filename of the file. |
path |
A string that will be treated as a path-like string as a single command-line argument; you can use ; or : as path separators and Ant will convert it to the platform's local conventions. |
pathref |
Reference to a path defined elsewhere. Ant will convert it to the platform's local conventions. |
line |
a space-delimited list of command-line arguments. |
It is highly recommended to avoid the line
version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.
Examples
<arg value="-l -a"/>
is a single command-line argument containing a space character, not separate commands "-l" and "-a".
<arg line="-l -a"/>
This is a command line with two separate arguments, "-l" and "-a".
<arg path="/dir;/dir2:\dir3"/>
is a single command-line argument with the value \dir;\dir2;\dir3
on DOS-based systems and /dir:/dir2:/dir3
on Unix-like systems.
Any project element can be assigned an identifier using its id
attribute. In most cases the element can subsequently be referenced by specifying the refid
attribute on an element of the same type. This can be useful if you are going to replicate the same snippet of XML over and over again--using a <classpath>
structure more than once, for example.
The following example:
<project ... >
<target ... >
<rmic ...>
<classpath>
<pathelement location="lib/"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</classpath>
</rmic>
</target>
<target ... >
<javac ...>
<classpath>
<pathelement location="lib/"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</classpath>
</javac>
</target>
</project>
could be rewritten as:
<project ... >
<path id="project.class.path">
<pathelement location="lib/"/>
<pathelement path="${java.class.path}/"/>
<pathelement path="${additional.path}"/>
</path>
<target ... >
<rmic ...>
<classpath refid="project.class.path"/>
</rmic>
</target>
<target ... >
<javac ...>
<classpath refid="project.class.path"/>
</javac>
</target>
</project>
All tasks that use nested elements for PatternSets, FileSets, ZipFileSets or path-like structures accept references to these structures as shown in the examples. Using refid
on a task will ordinarily have the same effect (referencing a task already declared), but the user should be aware that the interpretation of this attribute is dependent on the implementation of the element upon which it is specified. Some tasks (the property task is a handy example) deliberately assign a different meaning to refid
.
Ant supports a plugin mechanism for using third party tasks. For using them you have to do two steps:
- place their implementation somewhere where Ant can find them
- declare them.
Don't add anything to the CLASSPATH environment variable - this is often the reason for very obscure errors. Use Ant's own
mechanisms for adding libraries:
- via command line argument
-lib
- adding to
${user.home}/.ant/lib
- adding to
${ant.home}/lib
For the declaration there are several ways:
- declare a single task per using instruction using
<taskdef name="taskname" classname="ImplementationClass"/>
<taskdef name="for" classname="net.sf.antcontrib.logic.For" /> <for ... />
- declare a bundle of tasks using a properties-file holding these taskname-ImplementationClass-pairs and
<taskdef>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" /> <for ... />
- declare a bundle of tasks using a xml-file holding these taskname-ImplementationClass-pairs and
<taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml" /> <for ... />
- declare a bundle of tasks using a xml-file named antlib.xml, XML-namespace and
antlib:
protocoll handler
<project xmlns:ac="antlib:net.sf.antconrib"/> <ac:for ... />
If you need a special function, you should
- have a look at this manual, because Ant provides lot of tasks
- have a look at the external task page in the manual (or better online)
- have a look at the external task wiki page
- ask on the Ant user list
- implement (and share) your own
posted @
2008-12-05 13:41 张辰 阅读(374) |
评论 (0) |
编辑 收藏
1. 在src目录下面添加文件:HelloWorldTest.java
public class HelloWorldTest extends junit.framework.TestCase {
public void testNothing() {
}
public void testWillAlwaysFail() {
fail("An error message");
}
}
2.在lib目录下面添加junit.jar类
3.修改build.xml文件如下:
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="jar.dir" value="${build.dir}/jar" />
<property name="lib.dir" value="lib" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<property name="main-class" value="oata.HelloWorld" />
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" />
<copy todir="${classes.dir}">
<fileset dir="${src.dir}" excludes="**/*.java" />
</copy>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath" />
<path id="application" location="${jar.dir}/${ant.project.name}.jar" />
</classpath>
</java>
</target>
<target name="junit" depends="jar">
<junit printsummary="yes">
<classpath>
<path refid="classpath" />
<path refid="application" />
</classpath>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java" />
</batchtest>
</junit>
</target>
<target name="clean-build" depends="clean,jar" />
<target name="main" depends="clean,run" />
</project>
注:修改地方如下:
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath"/>
<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="junit" depends="jar">
<junit printsummary="yes">
<classpath>
<path refid="classpath"/>
<path refid="application"/>
</classpath>
<batchtest fork="yes">
<fileset dir="${src.dir}" includes="*Test.java"/>
</batchtest>
</junit>
</target>
6运行,得到结果:
...
junit:
[junit] Running HelloWorldTest
[junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0,01 sec
[junit] Test HelloWorldTest FAILED
BUILD SUCCESSFUL
...
posted @
2008-12-04 15:03 张辰 阅读(253) |
评论 (0) |
编辑 收藏
1.在上文基础上,修改源代码 HelloWorld.java
package oata;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class HelloWorld {
static Logger logger = Logger.getLogger(HelloWorld.class);
public static void main(String[] args) {
BasicConfigurator.configure();
logger.info("Hello World"); // the old SysO-statement
}
}
2. 在javademo目录下面添加lib目录,里面添加log4j的jar文件
3.修改build.xml,
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="jar.dir" value="${build.dir}/jar" />
<property name="lib.dir" value="lib" />
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<property name="main-class" value="oata.HelloWorld" />
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<classpath>
<path refid="classpath" />
<path location="${jar.dir}/${ant.project.name}.jar" />
</classpath>
</java>
</target>
<target name="clean-build" depends="clean,jar" />
<target name="main" depends="clean,run" />
</project>
4. 运行ant
posted @
2008-12-04 14:22 张辰 阅读(219) |
评论 (0) |
编辑 收藏
1.接上文,在javademo下面新建文件 build.xml
<project>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="oata.HelloWorld"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="build/jar/HelloWorld.jar" fork="true"/>
</target>
</project>
2.运行:
ant compile
ant jar
ant run
看到结果
注意:要在系统环境里面设置PATH到ant的bin目录
3.更加简便的打包:修改build.xml,为:
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="oata.HelloWorld"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
posted @
2008-12-04 11:50 张辰 阅读(393) |
评论 (0) |
编辑 收藏
reference:
http://ant.apache.org/manual/
1. 新建c:\javademo目录
2. 在javademo目录下,新建src\oata\文件夹
3.在oata目录下新建文件
package oata;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
4.在javademo目录下:
md build\classes
javac -sourcepath src -d build\classes src\oata\HelloWorld.java
java -cp build\classes oata.HelloWorld
可以看到结果:
Hello World
5.在javademo目录下:
echo Main-Class: oata.HelloWorld>myManifest
md build\jar
jar cfm build\jar\HelloWorld.jar myManifest -C build\classes .
java -jar build\jar\HelloWorld.jar
也可以看到结果:
Hello World
posted @
2008-12-04 11:29 张辰 阅读(127) |
评论 (0) |
编辑 收藏
1. 去c:新建一个目录 javademo (md javademo)
2.在目录下新建一个文件 : HelloWorldApp.java
class HelloWorldApp
{
public static void main(Stirng[] args)
{
System.out.println("Hello World!");
}
}
3. 保存后,在当前目录下面运行:javac HelloWorldApp.java
4.运行 java HelloWorldApp
posted @
2008-12-04 11:05 张辰 阅读(113) |
评论 (0) |
编辑 收藏
reference:
http://dev.yesky.com/275/2132275.shtml
1.在eclipse新建一个java project
2.新建一个class: hello, package = example, 代码如下:
package example;
public class hello
{
public int abs(int n)
{
return n >= 0 ? n : (-n);
}
}
3.右键点击hello.java,选择:new - junit test case
setUp / tearDown打钩, 最下方click here点击,添加JUnit.jar文件 - next
4.选择abs()方法
5.修改Hellotest代码:
package example;
import junit.framework.TestCase;
public class helloTest extends TestCase
{
private hello _hello;
protected void setUp() throws Exception
{
super.setUp();
_hello = new hello();
}
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testAbs()
{
assertEquals(_hello.abs(14), 14);
assertEquals(_hello.abs(-5), 5);
assertEquals(_hello.abs(0), 0);
}
}
6. 运行
posted @
2008-12-03 15:38 张辰 阅读(132) |
评论 (0) |
编辑 收藏
Oops! Eclipse + JSP + Applet + JMF Quick Start
Reference:
http://community.csdn.net/Expert/topic/5481/5481629.xml?temp=.1175043
applet的class文件最好不要放在web-inf目录下,因为这是个特殊目录
视频测试文件:
/Files/pixysoft/test.rar
Quick Start:
新建一个Dynamic Web Project项目,叫做Oops_JMF_Applet,然后修改project – properties,default output folder为:Oops_JMF_Applet/WebContent/classes
添加以下引用,全部可以在JMF包里面找到
在src目录下面增加一个文件:PlayerApplet.java
import java.applet.*;
import java.awt.*;
import java.net.*;
import javax.media.*;
public class PlayerApplet extends Applet implements ControllerListener
{
Player player = null;
public void init()
{
setLayout(new BorderLayout());
String mediaFile = getParameter("FILE");
try
{
URL mediaURL = new URL(getDocumentBase(), mediaFile);
player = Manager.createPlayer(mediaURL);
player.addControllerListener(this);
}
catch (Exception e)
{
System.err.println("Got exception " + e);
}
}
public void start()
{
player.start();
}
public void stop()
{
player.stop();
player.deallocate();
}
public void destroy()
{
player.close();
}
public synchronized void controllerUpdate(ControllerEvent event)
{
if (event instanceof RealizeCompleteEvent)
{
Component comp;
if ((comp = player.getVisualComponent()) != null)
add("Center", comp);
if ((comp = player.getControlPanelComponent()) != null)
add("South", comp);
validate();
}
}
}
在WebContent下面添加一个文件index.jsp。注意codebase问题
<html>
<body>
<APPLET CODE=PlayerApplet WIDTH=320 HEIGHT=300
codebase="/Oops_JMF_Applet/classes/">
<PARAM NAME=FILE VALUE="test.mpg">
</APPLET>
</body>
</html>
程序clean一下,在webContent目录下面添加一个test.mpg文件,然后选择index.jsp,Run on Server,选一个tomcat服务器,ok!
可惜不能截图。。。
posted @
2007-09-15 01:24 张辰 阅读(1095) |
评论 (0) |
编辑 收藏
Oops! Bea Sip Server Quick Start Part 2
Purpose
掌握由网页发出sip的invite请求。
Precondition:
http://www.blogjava.net/pixysoft/archive/2007/09/11/144131.html
Quick Start
在上一章,掌握了安装sip server,kapanga,然后写了一个注册的机制。这张写一个网页触发invite的事件,呼叫客户端。
首先建一个dynamic web project,叫做Oops_Sip_02,然后修改WebContent,改为invite,修改properties,把Default output folder改为:Oops_Sip_02/invite/WEB-INF/classes,删除build目录,最后整个项目为:
修改.classpath文件,增加3个引用:注意这3个引用是你安装目录下的。
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk150_06"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/wlss/wlss.jar"/>
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar" sourcepath="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar"/>
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/weblogic.jar"/>
<classpathentry kind="output" path="invite/WEB-INF/classes"/>
</classpath>
在src目录下面增加2个文件
httpControlServlet
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class httpControlServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doAction(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doAction(request, response);
}
private void doAction(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
String sip = request.getParameter("sip");
sipControlServlet.DoConnection(sip);
RequestDispatcher rds;
rds = getServletContext().getRequestDispatcher("/index.jsp");
rds.forward(request, response);
return;
}
}
sipControlServlet
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.sip.*;
import com.bea.wcp.sip.util.TransportUtil;
public class sipControlServlet extends SipServlet
{
private static Address myAddress;
private static SipFactory factory;
public void init(ServletConfig cfg) throws ServletException
{
super.init(cfg);
factory = (SipFactory) getServletContext().getAttribute(
SipServlet.SIP_FACTORY);
String uri = "sip:oops@localhost:5062";
myAddress = factory.createAddress(uri);
System.out.println("Oops! Sip Server Demo 2");
}
public static void DoConnection(String sip) throws ServletException,
IOException
{
SipApplicationSession appSession = factory.createApplicationSession();
Address to = factory.createAddress("sip:" + sip);
SipServletRequest invite = factory.createRequest(appSession, "INVITE",
myAddress, to);
invite.send();
System.out.println("Connection successful!");
}
protected void doResponse(SipServletResponse resp) throws ServletException,
IOException
{
resp.createAck().send();
}
}
在invite/WEB-INF下面建2个文件:
sip.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sip-app
PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN"
"http://www.jcp.org/dtd/sip-app_1_0.dtd">
<sip-app>
<display-name>Oops Sip Server Quick Start 2</display-name>
<distributable />
<servlet>
<servlet-name>sipControlServlet</servlet-name>
<servlet-class>sipControlServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- system user for the run-as element for Registrar -->
<security-role>
<role-name>system-user</role-name>
</security-role>
</sip-app>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testsender</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>httpControlServlet</servlet-name>
<servlet-class>httpControlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>httpControlServlet</servlet-name>
<url-pattern>/http.oops</url-pattern>
</servlet-mapping>
</web-app>
在invite目录下添加index.jsp
<html>
<body>
<form name="form_sip" action="http.oops"
method="post"><input name="sip" value="user1@192.168.0.130:5061"
type="text" style="width: 240px"><input type="submit"></form>
</body>
</html>
最后整个目录变为:
大概解说一下:用户网页输入sip,传递给后台httpservlet,其调用sipservlet的静态方法,创建一个会话到用户。
现在吧项目部署在bea sip server上面,方法参考前面的文章。然后在浏览器输入:
http://localhost:7001/invite
之后打开kapanga,在点击网页
完成!
posted @
2007-09-13 08:18 张辰 阅读(770) |
评论 (1) |
编辑 收藏
Oops! Bea Sip Server Quick Start Part 1
Purpose
掌握bea sip server 3.0
就是bea公司推出的一个sip的服务器,适合下一代电信网络。
首先声明一下,这个quick start比较有难度,我调了1个多小时才出来。很多很无聊的细节要注意!
Precondition:
sipserver300_win32.exe 328 MB (这个有点难度,可能需要去bea主页下载,还要申请)
kapanga 一个sip电话:http://www.kapanga.net/ip/download.cfm
Quick Start
Bea Sip Server 安装
首先当然是安装sipserver 3.0。很简单,根据提示没有问题,不过要注意,不要使用中文文件夹、不要过长的文件夹。
然后在sip server里面建立一个自己的domain,也很简单,不过要注意,要使用java jdk 1.5,不要使用其他的,否则有问题。然后在ie输入:
http://localhost:7001/console
就可以看到登录框!输入用户名和密码就可以进入:
Kapanga sip 电话安装
然后安装kapanga,需要配置,如图:
Username: user1
Display name: user1
Default URL: user1@192.168.0.130
注意,这个ip在运行 – cmd – ipconfig看到
Domain/realm: 192.168.0.130
sip proxy: 192.168.0.130:5060
outbound proxy: 192.168.0.130:5060
选择register
Local udp sip port: 5061
Eclipse 开发
然后关掉Kapanga,打开eclipse,新建一个项目Dynamic web project叫做Oops_Sip_01。注意以下设置:
然后确认之后生成项目目录。选择 project – properties – java build path – source,把default output folder修改为Oops_Sip_01/web/WEB-INF/classes。
确认后删除掉build目录,可以看到如下的结构
打开.classpath文件,修改如下,即引用了3个类,来自bea的sipserver,这个看大家的安装目录确定。
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src" />
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_02" />
<classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.web.container" />
<classpathentry kind="lib"
path="C:/bea/sipserver30/server/lib/wlss/wlss.jar" />
<classpathentry kind="lib"
path="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar"
sourcepath="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar" />
<classpathentry kind="lib"
path="C:/bea/sipserver30/server/lib/weblogic.jar" />
<classpathentry kind="output" path="web/WEB-INF/classes" />
</classpath>
在web " WEB-INF " lib目录下面添加以下jar文件,这些文件都可以在eclipse / plugin 里面和下载了jstl.jar文件包里面找到。没有的问我。
在web " WEB-INF"下添加文件夹tlds,添加以下文件:
在src目录下面添加3个java文件:
DisplayURIServlet 这里getRequestDispatcher("/index.jsp");很关键!
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class DisplayURIServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
session.setAttribute("user", UserController.Instance().GetList());
response.setContentType("text/html; charset=gb2312");
RequestDispatcher rds;
rds = getServletContext().getRequestDispatcher("/index.jsp");
rds.forward(request, response);
return;
}
}
Registration
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.sip.*;
public final class Registration extends SipServlet
{
public void init(ServletConfig sc) throws ServletException
{
super.init(sc);
System.out.println("Oops! First Sip Application!");
}
// 把用户保存起来
public void doRegister(SipServletRequest req) throws IOException,
ServletParseException
{
UserController.Instance().AddUser((SipURI) req.getTo().getURI());
SipServletResponse res = req.createResponse(200);
res.send();
}
}
UserController
import java.util.ArrayList;
import java.util.List;
import javax.servlet.sip.*;
public class UserController
{
List<SipURI> userList = new ArrayList<SipURI>();
private static UserController instance;
public static UserController Instance()
{
if (instance == null)
instance = new UserController();
return instance;
}
public void AddUser(SipURI url)
{
if (userList.contains(url))
return;
userList.add(url);
}
public List<SipURI> GetList()
{
return userList;
}
}
在web下面添加index.jsp文件
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<c:choose>
<c:when test="${empty sessionScope.user}">
Oops!No user!</c:when>
<c:otherwise>
<c:out value="${user}"/>
</c:otherwise>
</c:choose>
</body>
</html>
修改web/WEB-INF目录下的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>caonima</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
<servlet>
<servlet-name>user</servlet-name>
<servlet-class>
DisplayURIServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>user</servlet-name>
<url-pattern>/sip.oops</url-pattern>
</servlet-mapping>
</web-app>
在web/WEB-INF/目录下面添加2个xml文件:
sip.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sip-app
PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN"
"http://www.jcp.org/dtd/sip-app_1_0.dtd">
<sip-app>
<display-name>Oops! First SIP Servlet</display-name>
<distributable/>
<servlet>
<servlet-name>registrar</servlet-name>
<servlet-class>Registration</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- system user -->
<run-as>
<role-name>system-user</role-name>
</run-as>
</servlet>
<servlet-mapping>
<servlet-name>registrar</servlet-name>
<pattern>
<equal>
<var>request.method</var>
<value>REGISTER</value>
</equal>
</pattern>
</servlet-mapping>
<!-- system user for the run-as element for Registrar -->
<security-role>
<role-name>system-user</role-name>
</security-role>
</sip-app>
weblogic.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<run-as-role-assignment>
<role-name>system-user</role-name>
<run-as-principal-name>weblogic</run-as-principal-name>
</run-as-role-assignment>
</weblogic-web-app>
Ok!!完成了项目开发。整体目录如下:
选择project – clean命令编译项目
Sip Server部署
现在启动sip server,然后进入deployment页面:
点击lock & edit,然后可以点击install,来到你的项目位置,选择之后一直next到finish
激活你的部署:
同时在sip的Console可以看到一条语句:
然后选择你的项目,Start – serving all request,然后确定就好了!
打开ie,输入:http://localhost:7001/web/index.jsp,可以看到:
现在运行Kapanga,一定要注意设置,按照上面的设置:
然后再回到ie,输入:http://localhost:7001/web/sip.oops,可以看到:
一项艰巨的quick start完成!
posted @
2007-09-11 02:12 张辰 阅读(838) |
评论 (0) |
编辑 收藏
Oops! JMF Video Cam Quick Start(Java摄像头抓取)
Reference:
Oops! JMF Quick Start
http://www.blogjava.net/pixysoft/archive/2007/09/07/143408.html
JMF应用篇 之 从摄像头捕获视频
http://blog.csdn.net/sunny3106/archive/2007/05/06/1598143.aspx
Quick Start
安装jmf-2_1_1e-windows-i586.exe,可以在我的第一个JMF教程里面下载。然后运行JMF Registry,选择Capture Devices里面的Detect capture Devices,得到以下结果:
eclipse里面新建一个Java Project,名字叫做Oops_JMFCam。项目添加引用jmf.jar,在安装目录下面的lib找到。
在项目的src目录下面添加文件CaptureVideo.java。
import javax.media.*;
import java.io.*;
import java.awt.*;
classCaptureVideoextendsFrameimplementsControllerListener
{
privateCaptureDeviceInfo infor;
privateMediaLocator mediaLocator;
privateString url = "vfw:Microsoft WDM Image Capture (Win32):0";
privateComponent com;
privatePanel panel;
Player player;
public CaptureVideo()
{
infor = CaptureDeviceManager.getDevice(url);
mediaLocator = infor.getLocator();
}
publicvoid play()
{
try
{
player = Manager.createPlayer(mediaLocator);// 利用mediaLocator创建Player
player.addControllerListener(this);
player.realize();
// System.out.println("infor:"+infor);
// System.out.println("mediaLocator:"+mediaLocator);
}
catch (NoPlayerException e)
{
// TODO 自动生成 catch 块
e.printStackTrace();
}
catch (IOException e)
{
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
publicvoid createComponent()
{
setTitle("视频信号");
// addWindowListener(new WinClose());
setBounds(100, 100, 200, 200);
panel = newPanel();
if ((com = player.getVisualComponent()) != null)
{
panel.add(com);
}
add(panel);
setVisible(true);
}
publicsynchronizedvoid controllerUpdate(ControllerEvent arg0)
{
// TODO 自动生成方法存根
if (arg0 instanceofRealizeCompleteEvent)
{
System.out.println("realized");
createComponent(); // 将播放器添加到Panel上
player.prefetch();
}
if (arg0 instanceofPrefetchCompleteEvent)
{
player.start();
System.out.println("prefetched");
}
}
publicstaticvoid main(String[] arg0)
{
CaptureVideo video = newCaptureVideo();
video.play();
}
}
Run as Java Application,得到结果
posted @
2007-09-09 23:52 张辰 阅读(1627) |
评论 (0) |
编辑 收藏
不要看什么TestDriven之类的大道理。。
那些人为了提升一个小小的idea,于是写出了一大堆的废话来忽悠。就像xxx领导的yyy理论一样。
我们程序员需要的是实际。
其实,测试驱动的精髓在于:
不启动整个大型项目能够对某个小方法进行运行调试。
比如我在写一个大型网站,现在要测试数据库的调用之类的,但是我不能每次调试都启动整个网站,时间太长了,怎么办?
1.首先当然要实现了这个数据库调用类。
2.专门写一个testme.java文件,里面初始化这个类,传入参数,然后看结果
3.这个testme.java文件可以遵循JUnit之类的要求。
这样不用在整个项目里面添加一大堆测试类就能够测试了。而且testme.java文件是个临时文件,当测试通过直接就删了。
小结:
我们写程序为了验证某个方法是否可行,经常需要写个小程序去测试,这就是测试驱动。
posted @
2007-09-09 10:22 张辰 阅读(241) |
评论 (0) |
编辑 收藏
Oops! Access Ole Object Quick Start
Purpose:
操作accress的ole对象。并掌握测试驱动
Quick Start
新建一个名叫Oops_Access的项目java project。新建一个lib文件夹,导入以下类库
添加项目依赖性
在项目根目录加入一个demo.mdb文件(直接ctrl+C就可以进来了)
在demo.mdb数据库里面建立一张表,名字demo,表结构如下:
新建一个类,名叫DBController.java
import java.io.ByteArrayInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBController
{
public void Insert(String value)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=demo.mdb";
Connection con = DriverManager.getConnection(database, "", "");
String sql = "INSERT INTO DEMO (NAME,MEMO) VALUES(?,?)";
PreparedStatement pstm = null;
pstm = con.prepareStatement(sql);
pstm.setString(1, "Dr.Oops");
ByteArrayInputStream stream = new ByteArrayInputStream(value
.getBytes());
pstm.setBinaryStream(2, stream, stream.available());
pstm.execute();
pstm.close();
con.close();
}
catch (Exception e)
{
System.out.println("Error: " + e);
}
}
public String Select(String id)
{
String memo = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=demo.mdb";
Connection con = DriverManager.getConnection(database, "", "");
Statement s = con.createStatement();
s.execute("select ID,NAME,MEMO from DEMO where ID=" + id);
ResultSet rs = s.getResultSet();
if (rs != null)
{
while (rs.next())
{
byte[] image = rs.getBytes(3);
memo = new String(image, "gb2312");
}
}
s.close();
con.close();
}
catch (Exception e)
{
System.out.println("Error: " + e);
}
return memo;
}
}
新建一个TestMe.java文件
import junit.framework.TestCase;
public class TestMe extends TestCase
{
public void test()
{
DBController controller = new DBController();
controller.Insert("nice to meet you!");
System.out.println(controller.Select("1"));
}
}
然后Run as JUnit
posted @
2007-09-09 10:17 张辰 阅读(491) |
评论 (0) |
编辑 收藏
Oops! Hibernate + Access Quick Start
Purpose:
为了用hibernate链接access,花了我一个下午。他nnd,网上一群混蛋,没有一篇能够说明为什么的。
Reference:
Eclipse + Access
http://www.blogjava.net/pixysoft/archive/2007/08/30/141392.html
Eclipse + Hibernate
http://www.blogjava.net/pixysoft/archive/2007/09/01/141932.html
Quick Start:
所有的步骤参考上面的文章,几乎没有变,下面2个文件修改就行了。
假设我的access数据库保存在c:\demo.mdb,数据格式:
表名:CUSTOMER
字段:
id 自增,主键
username: 文本
password: 文本
则:
Customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="username" column="USERNAME" />
<property name="password" column="PASSWORD" />
</class>
</hibernate-mapping>
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.driver_class">
sun.jdbc.odbc.JdbcOdbcDriver<!-- 这里是Access的JDBCdriverclass名 -->
</property>
<property name="connection.url">
jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:/demo.mdb
</property>
<property name="connection.username">
sa
</property>
<property name="connection.password">
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping resource="Customer.hbm.xml" />
</session-factory>
</hibernate-configuration>
posted @
2007-09-08 17:36 张辰 阅读(1082) |
评论 (0) |
编辑 收藏
Oops! JMF Quick Start
Purpose:
学习完后能够学会操作JMF.
JMF是java media framework,能够控制流媒体
Reference :
http://blog.csdn.net/oscar999/archive/2006/12/11/1438694.aspx
Precondition:
Eclipse 3.3 europa
jmf-2_1_1e-windows-i586.exe
/Files/pixysoft/jmf-2_1_1e-windows-i586.part1.rar
/Files/pixysoft/jmf-2_1_1e-windows-i586.part2.rar
/Files/pixysoft/jmf-2_1_1e-windows-i586.part3.rar
/Files/pixysoft/jmf-2_1_1e-windows-i586.part4.rar
Quick Start:
新建一个java project,项目名为Oops_JMF
在项目里面添加一个lib目录,并添加以下jar文件,全部可以在jmf-2_1_1e-windows-i586.exe里面找到
在src目录下面添加以下文件:
SimpleAudioPlayer.java
import javax.media.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
public class SimpleAudioPlayer
{
private Player audioPlayer = null;
public SimpleAudioPlayer(URL url) throws IOException, NoPlayerException,
CannotRealizeException
{
audioPlayer = Manager.createRealizedPlayer(url);
}
public SimpleAudioPlayer(File file) throws IOException, NoPlayerException,
CannotRealizeException
{
this(file.toURL());
}
public void play()
{
audioPlayer.start();
}
public void stop()
{
audioPlayer.stop();
audioPlayer.close();
}
}
TestCase.java
import java.io.File;
import java.io.IOException;
import javax.media.CannotRealizeException;
import javax.media.NoPlayerException;
public class TestCase
{
/**
* @param args
*/
public static void main(String[] args)
{
File audioFile = new File("demo.mp3");
try
{
SimpleAudioPlayer player = new SimpleAudioPlayer(audioFile);
System.out.println("music begin");
player.play();
System.out.println("music end");
} catch (NoPlayerException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CannotRealizeException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
在项目根目录下面放置一个demo.mp3文件,最后整个项目变成:
右键点击项目,run as java application
设置好运行环境
成功!
发现很有趣。整个application运行完了,但是音乐还在继续。估计内部开了线程。
posted @
2007-09-07 14:56 张辰 阅读(897) |
评论 (0) |
编辑 收藏
Oops! JSF Quick Start!
Purpose:
学习使用一个JSF
Precondition:
/Files/pixysoft/jsf_simple_lib.part1.rar
/Files/pixysoft/jsf_simple_lib.part2.rar
Reference:
http://www.exadel.com/tutorial/jsf/jsftutorial-kickstart.html#compile
Tutorial:
新建一个项目Dynamic Web Project,名字Oops_JSF
在lib目录下添加以下jar文件
修改web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
在WEB-INF目录下面添加文件faces-config.xml
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<navigation-rule>
<from-view-id>/pages/inputname.jsp</from-view-id>
<navigation-case>
<from-outcome>greeting</from-outcome>
<to-view-id>/pages/greeting.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>personBean</managed-bean-name>
<managed-bean-class>jsfks.PersonBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
在WebContent下面添加pages目录,然后新建2个文件
greeting.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>
<html>
<head>
<title>greeting page</title>
</head>
<body>
<f:view>
<h3>
<h:outputText value="#{msg.greeting_text}"/>,
<h:outputText value="#{personBean.personName}"/>
<h:outputText value="#{msg.sign}"/>
</h3>
</f:view>
</body>
</html>
inputname.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:loadBundle basename="jsfks.bundle.messages" var="msg"/>
<html>
<head>
<title>enter your name page</title>
</head>
<body>
<f:view>
<h1>
<h:outputText value="#{msg.inputname_header}"/>
</h1>
<h:form id="helloForm">
<h:outputText value="#{msg.prompt}"/>
<h:inputText value="#{personBean.personName}"/>
<h:commandButton action="greeting" value="#{msg.button_text}"/>
</h:form>
</f:view>
</body>
</html>
在WebContent目录下面添加一个index.jsp文件
<html>
<body>
<jsp:forward page="/pages/inputname.jsf" />
</body>
</html>
在src目录下面添加jsfks目录,再添加PersonBean.java文件
package jsfks;
publicclass PersonBean {
String personName;
/**
*@returnPersonName
*/
public String getPersonName() {
returnpersonName;
}
/**
*@paramPersonName
*/
publicvoid setPersonName(String name) {
personName = name;
}
}
在jsfks目录下添加bundle目录,再添加文件messages.properties
inputname_header=JSFKickStart
prompt=Tellusyourname:
greeting_text=WelcometoJSF
button_text=SayHello
sign=!
最后整个文件夹为:
最后Run as … On Server
注意:一定要把之前的server配置删除,run as 的时候是一个新的server,就因为这个原因我忙了几个小时,才发现出错是因为之前存在了另外一个roject在server上,也不提示。
posted @
2007-09-04 18:39 张辰 阅读(355) |
评论 (0) |
编辑 收藏
Oops! JSP + XML Quick Start
/Files/pixysoft/xalan.part1.rar
/Files/pixysoft/xalan.part2.rar
新建一个Dynamic Web Project,名叫Oops_jsp_xml,然后在lib下添加以下jar文件,都可以在JSTL包里面找到。(xalan.jar文件这里下载,解压出来)。在WEB-INF下新建tlds目录,添加c.tld文件。
修改web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
在WebContent目录下面添加2个文件:
student.xml
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student id="1">
<name>
<first name="Joe1">Joe</first>
<last name="y1">Y</last>
<middle name="t1">T</middle>
</name>
<grade>
<points>99</points>
<letter>A</letter>
</grade>
</student>
<student id="2">
<name>
<first name="james1">James</first>
<last name="todd">Todd</last>
<middle name="k1">K</middle>
</name>
<grade>
<points>92</points>
<letter>B</letter>
</grade>
</student>
<student id="3">
<name>
<first name="kate1">Kate</first>
<last name="wang1">Wang</last>
<middle name="a1">A</middle>
</name>
<grade>
<points>72</points>
<letter>C</letter>
</grade>
</student>
</students>
index.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<html>
<head>
<title>index</title>
</head>
<body>
<c:import var="students" url="student.xml" />
<x:parse var="doc" xml="${students}"/>
<table border="1">
<tr>
<th>First</th>
<th>Last</th>
<th>Points</th>
<th>Letter</th>
</tr>
<x:forEach var="student" select="$doc/students/student">
<tr>
<td><x:out select="name/first/@name" /></td>
<td><x:out select="name/last" /></td>
<td><x:out select="grade/points" /></td>
<td><x:out select="grade/letter" /></td>
</tr>
</x:forEach>
</table>
</body>
</html>
运行!
posted @
2007-09-02 02:21 张辰 阅读(239) |
评论 (0) |
编辑 收藏