「Java」の編集履歴(バックアップ)一覧に戻る

Java - (2008/10/29 (水) 16:58:41) のソース

- 実行中のメソッド名を取得する。
new Throwable().getStackTrace()[0].getMethodName();

javascript:document.cookie;

- プレースホルダ
String year = yyyy.format(selectedDate);
String month = MM.format(selectedDate);
String date = dd.format(selectedDate);
Object[] dateArgs = { year, month, date };
MessageFormat form = new MessageFormat("{0}年{1}月{2}日"); 

- e.printStackTrace?()の文字列を取得する
StringWriter stringWriter = new StringWriter();
ex.printStackTrace(new PrintWriter(stringWriter));
String message = stringWriter.getBuffer().toString();

- ソースをShift_JISで書いて、EUC-JPで出力するってこと
<%@ page contentType=text/html; charset=EUC-JP" pageEncoding="Shift_JIS" %>

*Javaから、WEBブラウザを起動(Windowsのみ)
Runtime.getRuntime().exec( new String[] {
	"rundll32.exe",
	"url.dll,FileProtocolHandler",
	"http://jp.sun.com/" 
});

- WEBアプリケーションのルートを取得してパスを生成する
String root_path = this.getServletContext().getRealPath("/");
String file_path = root_path + "hoge.dat"


- Set-Cookie: UserName=lightbox
Cookie UserName = new Cookie( "UserName", "lightbox" );
response.addCookie( UserName );


- DOM取得
	public Document getDocument( String xml ){
		try {
			// ドキュメントビルダーファクトリを生成
			DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
			// ドキュメントビルダーを生成
			DocumentBuilder builder = dbfactory.newDocumentBuilder();
			// パースを実行してDocumentオブジェクトを取得
			System.out.println(getTextXml());
			Document doc = builder.parse( new ByteArrayInputStream( xml.getBytes("UTF-8") ) );
			
			return doc;
			// ルート要素を取得(タグ名:message)
			Element root = doc.getDocumentElement();
			// 最初の子ノード(テキストノード)の値を表示
			System.out.println(root.getFirstChild().getNodeName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
記事メニュー
目安箱バナー