取的话可以这样(文件名,文件简述等)String aa = myUpload.getRequest().getParameter("aa")
解决方案 »
- JSP中如何产生一个5位或6位不重复的随机数字?
- 求JSP+SQLserver2005或者MY SQL的同学录系统,有源码+数据库,谢谢,急用!
- 请各位高人帮我看看这段代码?为什么没有效果.
- 如何提高页面打开的速度?
- 50分问事务划分问题,急
- installanywhere学习
- 求JSP连接ACCESS的JAVABEAN
- 如何在 jsp中写一个类,接受一个参数 ,调用后再返回一个值呀
- 关于解决问题严重 [懒贴] [懒帐],贴出者跟分!
- 求助:struts1的配置问题
- jsp与mysql连接事,。jsp页中,通过什么读去db.properties的值呢? xiexie
- 用jdbcd调用数据库的问题
import javax.servlet.*;
import javax.naming.*;
import java.util.*;
import java.io.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class ParsePutFileHttpStream { private static final char CR = 13;
private static final char LF = 10; protected String boundary = null;
protected Hashtable params = new Hashtable();
private byte[] fileByte; public ParsePutFileHttpStream(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
ServletInputStream in = request.getInputStream();
BufferedInputStream bin = new BufferedInputStream(in);
boundary = getBoundary(request.getHeader("content-type")); PrintWriter out=response.getWriter();
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);
System.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");
System.out.println(" ...saving payload");
paserFileStream(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);
if (line.indexOf(boundary)>=0) System.out.println(line);
}
bytes = new byte[128];
}
out.println(this.fileByte.length);
} private void paserFileStream(BufferedInputStream is) throws IOException{
int c;
PushbackInputStream input = new PushbackInputStream(is, 128);
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((c=read(input,boundary))>=0) out.write(c);
fileByte=out.toByteArray();
out.close();
input.close();
} private String getParameter(ServletInputStream in)
throws java.io.IOException {
byte[] bytes = new byte[128];
in.readLine(bytes, 0, bytes.length);
return new String(bytes);
}
private String getBoundary(String contentType) {
int bStart = contentType.indexOf("boundary=")+"boundary=".length();
return "" + CR + LF + "--" + contentType.substring(bStart);
} private int read(PushbackInputStream input, String boundary)
throws IOException {
StringBuffer buffer = new StringBuffer();
int index = -1;
int c; do {
c = input.read();
buffer.append((char)c);
index++;
} while ((buffer.length() < boundary.length()) &&
(c == boundary.charAt(index)));
if (c == boundary.charAt(index)) {
int type = -1;
if (input.read() == '-')
type = -2;
while (input.read() != LF);
return type;
}
while (index >= 0){
input.unread(buffer.charAt(index));
index--;
}
return input.read();
} private Hashtable parseHeader(String line) {
Hashtable header = new Hashtable();
String token = null;
StringTokenizer st = new StringTokenizer(line, ";");
while (st.hasMoreTokens()) {
token = st.nextToken().trim();
String key = "";
String val = "";
int eq = token.indexOf("=");
if (eq < 0) eq = token.indexOf(":");
if (eq > 0) {
key = token.substring(0, eq).trim();
val = token.substring(eq+1);
val = val.replace('"',' ');
val = val.trim();
header.put(key, val);
}
}
return header;
} private void updateParams(Hashtable header) {
for(Enumeration e = header.keys(); e.hasMoreElements();) {
String key = (String)e.nextElement();
params.put(key, header.get(key));
}
} private void displayParams(PrintWriter out) {
for(Enumeration e = params.keys(); e.hasMoreElements();) {
String key = (String)e.nextElement();
System.out.println(" "+key+" = "+params.get(key));
}
} public byte[] getFileByte() {return this.fileByte;} public Object getParams(String param) {
return params.get(param);
} protected void finalize() {
params.clear();
params=null;
}}