Java路径,文件等
1. 在ServletFilter等Servlet web环境中,只要获得javax.servlet.ServletContext类型,则可以通过 getRealPath("...") 获得路径。相对路径中最顶层目录可通过参数“"/"”获取。request.getSession().getServletContext().getRealPath("/");2. JSP自定义标签javax.servlet.jsp.tagext.TagSupport((javax.servlet.ServletContext)pageContext).getRealPath("");3. 普通Java Class对象文件中使用:ServletContext servletContext = ServletActionContext.getServletContext();String pathName = ser
反射例子
import java.awt.Button;import java.lang.reflect.Method;import java.util.Hashtable;public class ReflectionTest { /** *@paramargs */ public static void main(String[] args) throws Exception { ReflectionTest reflection = new ReflectionTest(); reflection.getNameTest(); System.out.println(""); reflection.getMethodTest(); } /** *Class的getName()方法测试. *@throwsException */ public void getNameTest() throws Exception { S
简单属性配置文件
a) 属性配置文件portal.confarticle_img_path=search_images/rss_img/film_img_path=search_images/filmdetail1/history_img_path=search_images/historycontent333/advertisement_on=0advertisement1_url=http://172.21.153.81:8080/advert/ShowAdvertImage.action?frameId=10b)类文件:package com.utstar.tvweb.util;import java.util.Properties;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;public class Config extends Properties { private String fileName = "/portal.conf&q
Java读写XML文件例子2
import java.util.*;import javax.xml.parsers.*;import org.w3c.dom.*;import java.io.*;import org.apache.crimson.tree.XmlDocument;class Configure{private ArrayList student_Vector = new ArrayList();void readXMLFile(String inFile) throws Exception {//为解析XML作准备//创建DocumentBuilderFactory实例,指定DocumentBuilderDocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();DocumentBuilder db = null;try {db = dbf.newDocumentBuilder();} catch (ParserConfigurationException pce) {System.err.print
Java读写XML文件例子1
import java.util.*;import javax.xml.parsers.*;import org.w3c.dom.*;import java.io.*;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult;import javax.xml.transform.*;class Configure{private ArrayList student_Vector = new ArrayList();public static Hashtable Attribute(String configname,String mostlyelem,String childmostlyelem) throws Exception{Hashtable hs=new Hashtable();// DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();DocumentBuilder build
JDBC直接访问mysql数据库例子
import com.mysql.jdbc.Driver;import java.sql.Connection;import java.sql.Statement;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.io.*;import java.sql.*;public class Database {private Connection connection = null;public boolean Init( String url, String userName, String password) throws Exception{Class.forName("com.mysql.jdbc.Driver").newInstance();connection = DriverManager.getConnection(url, userName, password);return true;}public
Strut2.0学习笔记
开始了漫长的Strut2.0学习之路。[@more@]开始了漫长的Strut2.0学习之路。 记录学习过程。