----------厚厚發表于 2006年06月27日
網絡上很多關于JAVA對Oracle中BLOB、CLOB類型字段的操作說明,有的不夠全面,有的不夠準確,甚至有的簡直就是胡說八道。最近的項目正巧用到了這方面的知識,在這里做個總結。
一、BLOB操作 Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=839235 |
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
??? <script language="javascript">
//test function with post method
function RequestByPost(value)
{
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<soapenv:Envelope xmlns:xsi=";
data = data + '<soapenv:Body>';
data = data + '<ns1:getUser xmlns:ns1="http://ss/">';
data = data + '<Name>'+"ffff"+'</Name>';
data = data + '</ns1:getUser>';
data = data + '</soapenv:Body>';
data = data + '</soapenv:Envelope>';
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var URL="http://localhost:8080/myPj/SayHelloTo?wsdl";
xmlhttp.Open("POST",URL, false);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=UTF-8");
xmlhttp.SetRequestHeader ("SOAPAction","http://ss/SayHelloTo");
alert(data);
xmlhttp.Send(data);
alert( xmlhttp.responseText);
document.getElementById('mm').value=xmlhttp.responseText;
}
??? </script>
??? <title>
??????? Call webservice with javascript and xmlhttp.
??? </title>
??? <body>
???????
??????? <div id="mm">
??????? <input type="button" value="CallWebserviceByGet" onClick="RequestByGet(null)">
??????? <input type="button" value="CallWebserviceByPost" onClick="RequestByPost('Zach')">
??????? <input id="mm" type="text"/>
??? </body>
</html>
?
res://msxml.dll/defaultss.xslType | Value |
---|---|
int | 55 |
int | 676 |
<?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header/> <S:Body> <ns2:addTwo xmlns:ns2="http://my/"> <mm>55</mm> <gg>676</gg> </ns2:addTwo> </S:Body> </S:Envelope>
<?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:addTwoResponse xmlns:ns2="http://my/"> <return>731</return> </ns2:addTwoResponse> </S:Body> </S:Envelope>
程序員每天該做的事
1、總結自己一天任務的完成情況
最好的方式是寫工作日志,把自己今天完成了什么事情,遇見了什么問題都記錄下來,日后翻看好處多多
2、考慮自己明天應該做的主要工作
把明天要做的事情列出來,并按照優先級排列,第二天應該把自己效率最高的時間分配給最重要的工作
3、考慮自己一天工作中失誤的地方,并想出避免下一次再犯的方法
出錯不要緊,最重要的是不要重復犯相同的錯誤,那是愚蠢
4、考慮自己一天工作完成的質量和效率能否還能提高
一天只提高1%,365天你的效率就能提高多少倍你知道嗎? (1+0.01)^365 = 37 倍
function hel(){
?alert("good");
}?
Event.observe(document, 'mousedown', hel.bindAsEventListener());
? Browser: {
??? IE:???? !!(window.attachEvent && !window.opera),?//判斷是不是IE? 轉換為boolean
??? Opera:? !!window.opera,
??? WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
??? Gecko:? navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
? },
AnnotationProcessor
???? Annotation 處理的接口,實現類是DefaltAnnotationProcessor?:
protected static?void
|
lookupFieldResource
(javax.naming.Context?context, java.lang.Object?instance, java.lang.reflect.Field?field, java.lang.String?name)
??????????Inject resources in specified field. |
protected static?void
|
lookupMethodResource
(javax.naming.Context?context, java.lang.Object?instance, java.lang.reflect.Method?method, java.lang.String?name)
??????????Inject resources in specified method. |
?void
|
postConstruct
(java.lang.Object?instance)
??????????Call postConstruct method on the specified instance. |
?void
|
preDestroy
(java.lang.Object?instance)
??????????Call preDestroy method on the specified instance. |
?void
|
processAnnotations
(java.lang.Object?instance)
??????????Inject resources in specified instance |
public class DefaultAnnotationProcessor implements AnnotationProcessor {
???
??? protected javax.naming.Context context = null;
???
??? public DefaultAnnotationProcessor(javax.naming.Context context) {
??????? this.context = context;
??? }
??? /**
???? * Call postConstruct method on the specified instance.
???? */
??? public void postConstruct(Object instance)
??????? throws IllegalAccessException, InvocationTargetException {
???????
??????? Method[] methods = instance.getClass().getDeclaredMethods();
??????? Method postConstruct = null;
??????? for (int i = 0; i < methods.length; i++) {
??????????? if (methods[i].isAnnotationPresent(PostConstruct.class)) {
??????????????? if ((postConstruct != null)
??????????????????????? || (methods[i].getParameterTypes().length != 0)
??????????????????????? || (Modifier.isStatic(methods[i].getModifiers()))
??????????????????????? || (methods[i].getExceptionTypes().length > 0)
??????????????????????? || (!methods[i].getReturnType().getName().equals("void"))) {
??????????????????? throw new IllegalArgumentException("Invalid PostConstruct annotation");
??????????????? }
??????????????? postConstruct = methods[i];
??????????? }
??????? }
??????? // At the end the postconstruct annotated
??????? // method is invoked
??????? if (postConstruct != null) {
??????????? boolean accessibility = postConstruct.isAccessible();
??????????? postConstruct.setAccessible(true);
??????????? postConstruct.invoke(instance);
??????????? postConstruct.setAccessible(accessibility);
??????? }
???????
??? }
???
???
??? /**
???? * Call preDestroy method on the specified instance.
???? */
??? public void preDestroy(Object instance)
??????? throws IllegalAccessException, InvocationTargetException {
???????
??????? Method[] methods = instance.getClass().getDeclaredMethods();
??????? Method preDestroy = null;
??????? for (int i = 0; i < methods.length; i++) {
??????????? if (methods[i].isAnnotationPresent(PreDestroy.class)) {
??????????????? if ((preDestroy != null)
??????????????????????? || (methods[i].getParameterTypes().length != 0)
??????????????????????? || (Modifier.isStatic(methods[i].getModifiers()))
??????????????????????? || (methods[i].getExceptionTypes().length > 0)
??????????????????????? || (!methods[i].getReturnType().getName().equals("void"))) {
??????????????????? throw new IllegalArgumentException("Invalid PreDestroy annotation");
??????????????? }
??????????????? preDestroy = methods[i];
??????????? }
??????? }
??????? // At the end the postconstruct annotated
??????? // method is invoked
??????? if (preDestroy != null) {
??????????? boolean accessibility = preDestroy.isAccessible();
??????????? preDestroy.setAccessible(true);
??????????? preDestroy.invoke(instance);
??????????? preDestroy.setAccessible(accessibility);
??????? }
???????
??? }
???
???
??? /**
???? * Inject resources in specified instance.
???? */
??? public void processAnnotations(Object instance)
??????? throws IllegalAccessException, InvocationTargetException, NamingException {
???????
??????? if (context == null) {
??????????? // No resource injection
??????????? return;
??????? }
???????
??????? // Initialize fields annotations
??????? Field[] fields = instance.getClass().getDeclaredFields();
??????? for (int i = 0; i < fields.length; i++) {
??????????? if (fields[i].isAnnotationPresent(Resource.class)) {
??????????????? Resource annotation = (Resource) fields[i].getAnnotation(Resource.class);
??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
??????????? }
??????????? if (fields[i].isAnnotationPresent(EJB.class)) {
??????????????? EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);
??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
??????????? }
??????????? if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
??????????????? WebServiceRef annotation =
??????????????????? (WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);
??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
??????????? }
??????????? if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
??????????????? PersistenceContext annotation =
??????????????????? (PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);
??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
??????????? }
??????????? if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
??????????????? PersistenceUnit annotation =
??????????????????? (PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);
??????????????? lookupFieldResource(context, instance, fields[i], annotation.name());
??????????? }
??????? }
???????
??????? // Initialize methods annotations
??????? Method[] methods = instance.getClass().getDeclaredMethods();
??????? for (int i = 0; i < methods.length; i++) {
??????????? if (methods[i].isAnnotationPresent(Resource.class)) {
??????????????? Resource annotation = (Resource) methods[i].getAnnotation(Resource.class);
??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
??????????? }
??????????? if (methods[i].isAnnotationPresent(EJB.class)) {
??????????????? EJB annotation = (EJB) methods[i].getAnnotation(EJB.class);
??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
??????????? }
??????????? if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
??????????????? WebServiceRef annotation =
??????????????????? (WebServiceRef) methods[i].getAnnotation(WebServiceRef.class);
??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
??????????? }
??????????? if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
??????????????? PersistenceContext annotation =
??????????????????? (PersistenceContext) methods[i].getAnnotation(PersistenceContext.class);
??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
??????????? }
??????????? if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
??????????????? PersistenceUnit annotation =
??????????????????? (PersistenceUnit) methods[i].getAnnotation(PersistenceUnit.class);
??????????????? lookupMethodResource(context, instance, methods[i], annotation.name());
??????????? }
??????? }
??? }
???
???
??? /**
???? * Inject resources in specified field.
???? */
??? protected static void lookupFieldResource(javax.naming.Context context,
??????????? Object instance, Field field, String name)
??????? throws NamingException, IllegalAccessException {
???
??????? Object lookedupResource = null;
??????? boolean accessibility = false;
???????
??????? if ((name != null) &&
??????????????? (name.length() > 0)) {
??????????? lookedupResource = context.lookup(name);
??????? } else {
??????????? lookedupResource = context.lookup(instance.getClass().getName() + "/" + field.getName());
??????? }
???????
??????? accessibility = field.isAccessible();
??????? field.setAccessible(true);
??????? field.set(instance, lookedupResource);
??????? field.setAccessible(accessibility);
??? }
??? /**
???? * Inject resources in specified method.
???? */
??? protected static void lookupMethodResource(javax.naming.Context context,
??????????? Object instance, Method method, String name)
??????? throws NamingException, IllegalAccessException, InvocationTargetException {
???????
??????? if (!method.getName().startsWith("set")
??????????????? || method.getParameterTypes().length != 1
??????????????? || !method.getReturnType().getName().equals("void")) {
??????????? throw new IllegalArgumentException("Invalid method resource injection annotation");
??????? }
???????
??????? Object lookedupResource = null;
??????? boolean accessibility = false;
???????
??????? if ((name != null) &&
??????????????? (name.length() > 0)) {
??????????? lookedupResource = context.lookup(name);
??????? } else {
??????????? lookedupResource =
??????????????? context.lookup(instance.getClass().getName() + "/" + method.getName().substring(3));
??????? }
???????
??????? accessibility = method.isAccessible();
??????? method.setAccessible(true);
??????? method.invoke(instance, lookedupResource);
??????? method.setAccessible(accessibility);
??? }
???
}
? import java.lang.reflect.*;
public class RunTest {
??? public static void main(String[] args) throws Exception {
???????
??????? int passed = 0, failed = 0;
??????? for (Method m : Class.forName("Foo").getMethods()) {
??????????? if (m.isAnnotationPresent(Test.class)) {
??????????????? try {
??????????????????? m.invoke(null);
???????????????????
??????????????????? passed++;
??????????????? } catch (Throwable ex) {
??????????????????? System.out.printf("Test %s failed: %s %n", m, ex.getCause());
??????????????????? failed++;
??????????????? }
??????????? }
??????? }
??????? System.out.printf("Passed: %d, Failed %d%n", passed, failed);
??? }
}
public class Foo {
??? @Test public static void m1() {
??? System.out.println("m1 SUcsessful");
??? }
??? public static void m2() { }
??? @Test public static void m3() {
??????? System.out.println("m3 Fails");
??????? throw new RuntimeException("Boom");
??? }
??? public static void m4() { }
??? @Test public static void m5() { }
??? public static void m6() { }
??? @Test public static void m7() {
??????? throw new RuntimeException("Crash");??????? }
???
??? public static void m8() { }
}
import java.lang.annotation.*;
/*
?* Test.java
?*
?* Created on 2007年6月28日, 上午8:52
?*
?* To change this template, choose Tools | Template Manager
?* and open the template in the editor.
?*/
/**
?*
?* @author ljl
?*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Test {
???
???
???
}
/** The original page id sent from the server */
dwr.engine._origScriptSessionId = "${scriptSessionId}";
/** The session cookie name */
dwr.engine._sessionCookieName = "${sessionCookieName}"; // JSESSIONID
以上這段代碼取自? dwr?源碼包中?engine.js
這里的${scriptSessionId}?? 與? ${sessionCookieName} 是從哪里或得的,又是怎么獲得的呢。
有怎么會用? ${}? ,${}?是什么意思呢?請各位大俠不吝賜教!