Java Reference
In-Depth Information
protected String boundary = null;
protected Hashtable params = new Hashtable();
public void doPost( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException{
ServletOutputStream out = response.getOutputStream();
ServletInputStream in = request.getInputStream();
BufferedInputStream bin = new BufferedInputStream(in);
boundary = getBoundary(request.getHeader("content-type"));
out.println("<html><body><pre>");
out.println("boundary =\n"+boundary);
out.println();
byte[] bytes = new byte[128];
in.readLine(bytes,0,bytes.length);
String line = new String(bytes);
Hashtable header = null;
while(in.readLine(bytes,0,bytes.length)>=0){
line = new String(bytes);
if(line.startsWith("Content-Disposition:")){
out.println(line);
header = parseHeader(line);
updateParams(header);
}else if(line.startsWith("Content-Type:")){
params.put("Content-Type",
line.substring("Content-Type:".length()).trim());
}else{
if(header!=null&&bytes[0]==13){
if(header.containsKey("filename")){
displayParams(out);
out.println(" ...saving payload");
savePayload(params,bin);
header = null;
}else{
String name = (String)header.get("name");
String value = getParameter(in).trim();
params.put(name,value);
}
}if(line.indexOf(boundary)>=0)out.println(line);
}
Search WWH ::




Custom Search