In Oracle/PLSQL, the userenv function can be used to retrieve information about the current Oracle session. Although this function still exists in Oracle for backwards compatibility, it is recommended that you use the sys_context function instead.
The syntax for the userenv function is:
userenv( parameter )
parameter is the value to return from the current Oracle session. The possible values are:
Parameter Explanation CLIENT_INFO Returns user session information stored using the DBMS_APPLICATION_INFO package ENTRYID Available auditing entry identifier INSTANCE The identifier number of the current instance ISDBA Returns TRUE if the user has DBA privileges. Otherwise, it will return FALSE. LANG The ISO abbreviation for the language LANGUAGE The language, territory, and character of the session. In the following format:
???? language_territory.charactersetSESSIONID The identifier of the auditing session TERMINAL The OS identifier of the current session
For example:
摘要: javaScript技巧集合 事件源對象 event.srcElement.tagName event.srcElement.type 捕獲釋放 event.srcElement.setCapture();? eve... 閱讀全文
userenv('ENTRYID') would return FALSE userenv('LANGUAGE') would return 'AMERICAN_AMERICA.WE8DEC'
Session.load/get方法均可以根據指定的實體類和id從數據庫讀取記錄,并返回與之對應的實體對象。其區別在于:
Session在加載實體對象時,將經過的過程:
|
做webservice 盡量將具體的實現寫在javabean里,這樣可以減少客戶網站和webservice的耦合,就是說你修改了具體的實現之后,客戶網站并不需要重新部署,從而提高開發效率提高
摘要: 閱讀全文 function strLen(str) {/*
?* ViewUploadFile.java
?*
?* Created on 2006年2月4日, 上午1:29
?*/
package path.system.manager;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.hibernate.Session;
import system.entity.CRM_UploadFile;
import.FileStorageService;
public class ViewUploadFile extends HttpServlet {
??? private FileInputStream isFile = null;
???
??? /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
???? * @param request servlet request
???? * @param response servlet response
???? */
??? protected void processRequest(HttpServletRequest request, HttpServletResponse response)
??? throws ServletException, IOException {
??????? String szCoObject=request.getParameter("CoObject");
??????? String szID=request.getParameter("ID");
??????? String szMode = request.getParameter("Mode");
???????
??????? //清空緩沖
??????? response.reset();
???????
??????? OutputStream osOut = response.getOutputStream();
???????
??????? if(szID == null || szID.equals("") || szID.equals("0"))
??????? {??
??????????? byte[] cFileData = this.getNoDate (szCoObject);
???????????
??????????? this.isFile.read(cFileData);
??????????? osOut.write(cFileData);
??????? }
??????? else
??????? {
??????????? Session ssSession = HibernateUtil.getSession();
??????????? CRM_UploadFile csUpload;
??????????? csUpload = (CRM_UploadFile)ssSession.load(CRM_UploadFile.class,Integer.valueOf(szID));
??????????? String szFileName =csUpload.getFileName();
??????????? if (szFileName==null) szFileName = "";
??????????? String szRightName = new String( szFileName.getBytes(), "ISO8859_1" );????? //中文文件名處理
??????????? String szFileSize = csUpload.getFileSize().toString();
??????????? String urlFileName = csUpload.getUrlFileName();
///輸出到網頁
??????????? if ("0".equals(szFileSize)) {
??????????????? byte[] cFileData = this.getNoDate(szCoObject);
??????????????? this.isFile.read(cFileData);
??????????????? osOut.write(cFileData);
??????????? } else {
??????????????? if(szMode.equals("Download")) {
??????????????????????? response.setContentType("application/x-msdownload;");?????????? //下載類型
??????????????????????? response.setHeader("Content-Disposition","attachment; filename=" + szRightName);
??????????????? } else {
??????????????????????? response.setContentType(csUpload.getContentType());
??????????????????????? response.setHeader("Content-Disposition","filename=" + szRightName);
??????????????? }
??????????????? response.setHeader("content-length", szFileSize);
??????????????? //java.sql.Blob blob = csUpload.getBinaryData();
??????????????? File file = new File(FileStorageService.getRootPath() + urlFileName);
??????????????? if (!file.exists())
??????????????????? return;
???????????????
??????????????? InputStream bis = new BufferedInputStream(new FileInputStream(file));
??????????????? byte[] buffer = new byte[2048];
??????????????? for (int i = bis.read(buffer); i > 0; i = bis.read(buffer))
??????????????????? osOut.write(buffer, 0, i);
??????????????? bis.close();
???????????????????
??????????? }
??????? }
???????
??????? //防止超時
??????? //response.setStatus( response.SC_OK );
??????? response.flushBuffer();
??? }
???
??? private byte[] getNoDate (String szCoObject) throws IOException{
??????? String szFileName="";
??????? if(szCoObject.equals("Employee"))
??????????? szFileName = getServletContext().getRealPath("/images/Employee/NoPhoto.gif");
??????? else
??????????? szFileName = getServletContext().getRealPath("/images/Commodity/NoPhoto.gif");
??????? this.isFile= new FileInputStream(szFileName);
??????? int nSize = this.isFile.available();
??????? byte[] cFileData = new byte[nSize];
??????? return cFileData;
??? }
??? // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
??? /** Handles the HTTP <code>GET</code> method.
???? * @param request servlet request
???? * @param response servlet response
???? */
??? protected void doGet(HttpServletRequest request, HttpServletResponse response)
??? throws ServletException, IOException {
??????? processRequest(request, response);
??? }
???
??? /** Handles the HTTP <code>POST</code> method.
???? * @param request servlet request
???? * @param response servlet response
???? */
??? protected void doPost(HttpServletRequest request, HttpServletResponse response)
??? throws ServletException, IOException {
??????? processRequest(request, response);
??? }
???
??? /** Returns a short description of the servlet.
???? */
??? public String getServletInfo() {
??????? return "Short description";
??? }
??? // </editor-fold>
}
public final int read(byte[]?b) throws IOException
b
中。以整數形式返回實際讀取的字節數。在輸入數據可用、檢測到文件末尾 (end of file) 或拋出異常之前,此方法將一直阻塞。
如果 b
為 null,則拋出 NullPointerException
。如果 b
的長度為零,則不讀取字節并返回 0
;否則試圖讀取至少一個字節。如果因為該流在文件末尾而無字節可用,則返回值 -1
;否則至少讀取一個字節并將其存儲到 b
中。
將讀取的第一個字節存儲到元素 b[0]
中,將下一個字節存儲到 b[1]
中,依此類推。讀取的字節數至多等于 b
的長度。設 k
為實際讀取的字節數;這些字節將存儲在從 b[0]
到 b[k-1]
的元素中,b[k]
到 b[b.length-1]
的元素不受影響。
如果因為文件末尾以外的其他原因而無法讀取第一個字節,則拋出 IOException
。尤其在輸入流已關閉的情況下,將拋出 IOException
。
read(b)
方法與以下方法的效果相同:
read(b, 0, b.length)
import java.io.*;
import java.net.*;
public class Test {
??? public boolean saveUrlAs(String photoUrl, String fileName) {
??????? //此方法只能用于HTTP協議
??????? try {
??????????? URL url = new URL(photoUrl);
??????????? HttpURLConnection connection = (HttpURLConnection) url.
??????????????????? openConnection();
??????????? DataInputStream in = new DataInputStream(connection.getInputStream());
??????????? DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
??????????? byte[] buffer = new byte[4096];
??????????? int count = 0;
??????????? while ((count = in.read(buffer)) > 0) {
??????????????? out.write(buffer, 0, count);
??????????? }
??????????? out.close();
??????????? in.close();
??????????? return true;
??????? } catch (Exception e) {
??????????? return false;
??????? }
??? }
???
??? public String getDocumentAt(String urlString) {
??????? //此方法兼容HTTP和FTP協議
??????? StringBuffer document = new StringBuffer();
??????? try {
??????????? URL url = new URL(urlString);
??????????? URLConnection conn = url.openConnection();
??????????? BufferedReader reader = new BufferedReader(new InputStreamReader(
??????????????????? conn.getInputStream()));
??????????? String line = null;
??????????? while ((line = reader.readLine()) != null) {
??????????????? document.append(line + "\n");
??????????? }
??????????? reader.close();
??????? }catch (MalformedURLException e) {
??????????? System.out.println("Unable to connect to URL: " + urlString);
??????? }catch (IOException e) {
??????????? System.out.println("IOException when connecting to URL: " +
??????????????????? urlString);
??????? }
??????? return document.toString();
??? }
???
??? public static void main(String[] args) throws IOException {
??????? Test test = new Test();
??????? String photoUrl = "??????? String fileName = photoUrl.substring(photoUrl.lastIndexOf("/"));
??????? String filePath = "c:";
??????? boolean flag = test.saveUrlAs(photoUrl, filePath + fileName);
??????? System.out.println("Run ok!\nGet URL file " + flag);
??? }
}
?
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/*
?* hello.java
?*
?* Created on 2007年8月3日, 上午11:15
?*
?* To change this template, choose Tools | Template Manager
?* and open the template in the editor.
?*/
/**
?*
?* @author ljl
?*/
public class hello {
???
??? /** Creates a new instance of hello */
??? public hello() {
??? }
??? public static void main(String s[]) throws Exception{
??????? String sss="Sogood";
?????? // System.out.print(sss.substring(0,4));
??????? ReadURL("??? }
??? public static void ReadURL(String URLName) throws Exception // 如果發生異常則向上拋出
??? {
??????? int HttpResult; // 服務器返回的狀態
??????? URL url =new URL(URLName); // 創建URL
???????
??????? URLConnection urlconn = url.openConnection(); // 試圖連接并取得返回狀態碼
??????? urlconn.connect();
??????? HttpURLConnection httpconn =(HttpURLConnection)urlconn;
??????? HttpResult = httpconn.getResponseCode();
??????? System.out.println(HttpResult);
??????? if(HttpResult != HttpURLConnection.HTTP_OK) // 不等于HTTP_OK說明連接不成功
?????????? System.out.print("fail");
??????? else {
??????????? int filesize = urlconn.getContentLength(); // 取數據長度
??????????? System.out.println(filesize);
??????????? InputStreamReader isReader = new InputStreamReader(urlconn.getInputStream());
??????????? char[] buffer = new char[2048]; // 創建存放輸入流的緩沖
??????????? int num = 0; // 讀入的字節數
??????????? while(num>-1) {
??????????????? num = isReader.read(buffer); // 讀入到緩沖區
??????????????? if(num < 0) break; // 已經讀完
??????????????? System.out.print("suc");
????????????? System.out.println(new String(buffer,0,num)); // 顯示出來
??????????? }
??????????? isReader.close();//關閉輸入流
??????? }
??? }
???
???
}
404:服務器找不到指定的資源,請求的網頁不存在(譬如瀏覽器請求的網頁被刪除或者移位,但不排除日后該鏈接有效的可能性);32C站長資訊
410:請求的網頁不存在(注意:410表示永久性,而404表示臨時性);32C站長資訊
200:服務器成功返回請求的網頁;32C站長資訊
301:網址永久性重定向32C站長資訊
302:網址臨時性重定向
一般
Singleton
模式通常有幾種種形式:
第一種形式:定義一個類,它的構造函數為
private
的,它有一個
static
的
private
的該類變量,在類初始化時實例話,通過一個
public
的
getInstance
方法獲取對它的引用
,
繼而調用其中的方法。
public class Singleton {
private Singleton(){}
//
在自己內部定義自己一個實例,是不是很奇怪?
//
注意這是
private
只供內部調用
private static Singleton instance = new Singleton();
//
這里提供了一個供外部訪問本
class
的靜態方法,可以直接訪問
public static Singleton getInstance() {
return instance;
}
}
?
第二種形式:
public class Singleton {
private static Singleton instance = null;
public static synchronized Singleton getInstance() {
//
這個方法比上面有所改進,不用每次都進行生成對象,只是第一次
//
使用時生成實例,提高了效率!
if (instance==null)
instance
=
new Singleton();
return instance;
}
}
switch
(
expr1
)中,
expr1
是一個整數表達式。因此傳遞給
switch
和
case
語句的參數應該是
int
、
short
、
char
或者
byte
。
long,string
都不能作用于
swtich
。
會執行,在 return 前執行。
Overload 和 Override 的區別。 Overloaded 的方法是否可以改變返回值的類型 ?方法的重寫 Overriding 和重載 Overloading 是 Java 多態性的不同表現。重寫 Overriding 是父類與子類之間多態性的一種表現,重載 Overloading 是一個類中多態性的一種表現。如果在子類中定義某方法與其父類有相同的名稱和參數,我們說該方法被重寫 (Overriding) 。子類的對象使用這個方法時,將調用子類中的定義,對它而言,父類中的定義如同被“屏蔽”了。如果在一個類中定義了多個同名的方法,它們或有不同的參數個數或有不同的參數類型,則稱為方法的重載 (Overloading) 。 Overloaded 的方法是可以改變返回值的類型
數組有沒有 length() 這個方法 ? String 有沒有 length() 這個方法?
數組沒有
length()
這個方法,有
length
的屬性。
String
有有
length()
這個方法。
sleep:在睡覺,要睡夠了你才叫得醒 wait:在等你叫它 |
TOP |
回復人:Polarislee(北極星)(灌水是我無言的抗議)??一星(中級)??信譽:110??????2005-3-1 13:35:27??得分:20 |
sleep是Thread類的靜態方法。sleep的作用是讓線程休眠制定的時間,在時間到達時恢復,也就是說sleep將在接到時間到達事件事恢復線程執行,例如: try{ System.out.println("I'm going to bed"); Thread.sleep(1000); System.out.println("I wake up"); } catch(IntrruptedException e) { } wait是Object的方法,也就是說可以對任意一個對象調用wait方法,調用wait方法將會將調用者的線程掛起,直到其他線程調用同一個對象的notify方法才會重新激活調用者,例如: //Thread 1 try{ obj.wait();//suspend thread until obj.notify() is called } catch(InterrputedException e) { } |
16
,
Collection
和
Collections
的區別。
Collections
是個
java.util
下的類,它包含有各種有關集合操作的靜態方法。
Collection 是個 java.util 下的接口,它是各種集合結構的父接口。