Request:
HttpServletRequestrequest=ServletActionContext.getRequest();
Response:
HttpServletResponseresponse=ServletActionContext.getResponse();
Session(HttpSession):
HttpSession session= request.getSession();
application:
ServletContext application=pageContext. getServletContext();
Session(org.hibernate.Session):
Sessionsession=HibernateUtil.openSession();
Cookies:
Cookie[]cookies=request.getCookies();//通过请求获取到cookie
Out:
PrintWriterout=resp.getWriter();//(HttpServletResponse resp)
Context:
ServletContextcontext=req.getSession().getServletContext();
属性文件Properties:
Map<String,String> properties = new HashMap<String, String>();
系统属性Properties:
Properties properties=System.getProperties();
properties.list(System.out); //打印系统属性
persons:泛型,只能保存一种类型
List<person> persons=newArrayList<person>();
Persons对象遍历:
for(person stu: persons){ System.out.println(stu.getPersonName());
}
List: 泛型,只能保存一种类型
List<String>list=new ArrayList<String>();
Set:
Set<Integer>set = new HashSet<Integer>();
arrayList:
ArrayList arrayList=new ArrayList();
hashMap:
HashMap hashMap=new HashMap();
hashSet:
HashSet hashSet=new HashSet();
linkedList:
LinkedList linkedList=new LinkedList();
键映射到值:
Map<Integer,student>students=new HashMap<Integer,student>();
请求转发:
RequestDispatcherrd=req.getRequestDispatcher("login.jsp");
rd.forward(req,resp);或者
req.getRequestDispatcher("index.jsp").forward(req,resp);
重定向:
resp.sendRedirect("login.jsp”);
转换成包装类:
int i=3;
Integer in=new Integer(i);
runtime:
Runtime runtime=Runtime.getRuntime();
Process p= runtime.exec("java Test");
InputStream is=p.getInputStream();
int data;
while((data=is.read())!=-1){
System.out.println((char)data);
}
线程:
Thread1 t1=new Thread1();
for循环遍历:
String[]a={"wo","men"};
for(String iii:a){
System.out.println(iii);
}
迭代器:
Collection c;
Iterator it=c.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
字符流写入文件:
FileOutputStream fos=new FileOutputStream("test.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
BufferedWriter bw=new BufferedWriter(osw);
bw.write("http://www.mybole.com.cn");
bw.close();
字符流读取文件:
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader br=new BufferedReader(isr);
System.out.println(br.readLine());//按行读取,只有一行,直接读取
br.close();
字节流到字符流的转换:
InputStreamReader isr2=new InputStreamReader(System.in);
BufferedReader br2=new BufferedReader(isr2);
String StrLine;
while((StrLine=br2.readLine())!=null){
System.out.println(StrLine);
}
br2.close();
写入字节流:
FileOutputStream fos=newFileOutputStream("1.txt");
fos.write("http://www.baidu.com".getBytes());
fos.close();//关闭*/
读取字节流:
FileInputStream fis=newFileInputStream("1.txt");
byte[] buf=new byte[100];
int len=fis.read(buf);
System.out.println(new String(buf,0,len));
fis.close();//关闭*/
文件创建:
File f1=new File("1.txt");//都是相对路径,在项目文件夹中产生
f1.createNewFile(); //创建一个新文件
f1.mkdir();//创建一个目录//也就是一个文件夹
得到当前Test类文件的所在目录:
URL url=Test.class.getResource("");
URI uri=null;
uri = url.toURI();
//例如file:/D:/java/studentJava/bin/util/
//util为Test.java所在的包
获取源文件夹的文件或目录:
String path = "G:\\abc";
File[] file=new File(path).listFiles();