取的话可以这样(文件名,文件简述等)String aa = myUpload.getRequest().getParameter("aa")
解决方案 »
- jsp如何查找mysql中的内容代码如何实现
- 请帮我解决这个问题
- 使用ScriptX.cab控件页面打印时报javascript error!
- 请问怎样
- 基于struts架构的java web 程序如何有效的调试程序
- 初学jsp,生成一个数据库连接后,如何在别的页面也能够调用这个连接?还有其他几个相关问题
- 菜鸟的问题。请各位帮帮忙,我提交好没有出现我字符帮看一下怎么回事谢谢。
- 一个小问题!
- 往数据库中写数据的语句中,书上的三个“撇”一模一样,区分不开,请帮忙(rookie2002
- 为什么我的servlet得出来的中文是乱法,要如何做呢
- 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;
}}