






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Ye Wu
http://www.ise.gmu.edu/~wuye/
SWE 642 Software Engineering for the World Wide Web
sources: Java for the Web with Servlets, JSP and EJB, Kurniawan, New Riders Professional Java Server Programming, Patzer, Wrox
2006-2-27 Ā© Dr. Wu and Dr. Offutt 2
getParameter(), getParameterValues(), getParameterName()
getAttribute(), getAttributeNames(), setAttribute(), removeAttribute()
getInputStream(), getReader()
getPathInfo(), getPathTranslated(), getQueryString() getRequestURI(), getServletPath() HelloRequest.java
2006-2-27 Ā© Dr. Wu and Dr. Offutt 3
--AaB03x content-disposition: form-data; name="field1"
Joe Blow --AaB03x content-disposition: form-data; name="pics"; filename="file1.txt" Content-Type: text/plain
... contents of file1.txt ... FileLoad.java & FileUpload.java --AaB03x--
2006-2-27 Ā© Dr. Wu and Dr. Offutt 4
2006-2-27 Ā© Dr. Wu and Dr. Offutt 7
Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { name = item.getFieldName(); value = item.getString();} else { name = item.getFieldName(); filename = item.getName(); formDatalength = item.getSize(); File uploadedFile = new File("test_file"); item.write(uploadedFile);} }
2006-2-27 Ā© Dr. Wu and Dr. Offutt 8
2006-2-27 Ā© Dr. Wu and Dr. Offutt 9
2006-2-27 Ā© Dr. Wu and Dr. Offutt 10
2006-2-27 Ā© Dr. Wu and Dr. Offutt 13
Static files
2006-2-27 Ā© Dr. Wu and Dr. Offutt 14
Step1: set responseās content type to:
Step2: Add an HTTP response header named
Content-disposition (RFC 2183)
Step3: Set data to the client
2006-2-27 Ā© Dr. Wu and Dr. Offutt 15
res.setContentType("APPLICATION/PDF"); //res.setContentType("APPLICATION/X-DOWNLOAD"); OutputStream out = res.getOutputStream(); String fname = "d:/a.pdf"; res.setHeader("Content-Disposition", "attachement; filename=a.pdf"); FileInputStream fis = new FileInputStream(fname); int i; while ((i=fis.read()) != -1) { out.write(i); } out.flush(); fis.close(); out.close();
2006-2-27 Ā© Dr. Wu and Dr. Offutt 16
URL url = new URL ( fileURL ); URLConnection conn = url.openConnection();
String authentication = "Basic " + new sun.misc.BASE64Encoder().encode("username:password".getBytes());
System.getProperties().put("proxySet", "true"); System.getProperties().put("proxyHost", PROXY_HOST); // your proxy host System.getProperties().put("proxyPort", PROXY_PORT); // your proxy port conn.setRequestProperty("Proxy-Authorization", authentication); BufferedInputStream bis = new BufferedInputStream(url.openStream());
2006-2-27 Ā© Dr. Wu and Dr. Offutt 19
---- There are tons of similar stuff on web, this is just something Iām using
2006-2-27 Ā© Dr. Wu and Dr. Offutt 20
Download file http://www.acme.com/resources/classes/Acme.tar.gz Unzip the file; Create a jar file by using the following command: Jar cf acme.jar ā¦directoryname⦠Add the acme.jar file into your CLASSPATH
2006-2-27 Ā© Dr. Wu and Dr. Offutt 21
content types(Follow the format of rfc1876)
Response.setContentType(āmultipart/x-mixed- replace;boundary=Endā);
Out.println(āContent-Type: ā + countentType); Outprintln();
Out.println(ā--Endā); ServerPush.java
2006-2-27 Ā© Dr. Wu and Dr. Offutt 22
Refresh Interval
Refresh until itās ready