Topic: 问:我通过vb(xmlhttp)提交过来的文件,jsp怎样接收?下面是asp的,那位高人改改

  Print this page

1.问:我通过vb(xmlhttp)提交过来的文件,jsp怎样接收?下面是asp的,那位高人改改 Copy to clipboard
Posted by: itking
Posted on: 2004-09-06 11:09

<%@ LANGUAGE=VBScript%>
<% Option Explicit
Response.Expires = 0

dim ado_stream
dim xml_dom
Dim i
Dim UpPath
dim CurrentFileName
Dim oNodelist
Dim currNode

'注意:这个文件夹一定要存在的
UpPath = Server.MapPath("\") & "\upload\"

set ado_stream = Server.CreateObject("ADODB.Stream")
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")
xml_dom.load(request)

Set oNodelist = xml_dom.selectNodes("/root/file")
For i = 0 To oNodelist.length - 1
Set currNode = oNodelist.Item(i).selectSingleNode("filename")
CurrentFileName = currNode.Text

Set currNode = oNodelist.Item(i).selectSingleNode("fileContent")
ado_stream.Type = 1 ' 1=adTypeBinary
ado_stream.open

ado_stream.Write currNode.nodeTypedValue
ado_stream.SaveToFile UpPath & CurrentFileName,2 ' 2=adSaveCreateOverWrite
ado_stream.close
Next
set ado_stream = Nothing
set xml_dom = Nothing
Response.Write "Upload successful!"
%>

2.Re:问:我通过vb(xmlhttp)提交过来的文件,jsp怎样接收?下面是asp的,那位高人改改 [Re: itking] Copy to clipboard
Posted by: itking
Posted on: 2004-09-06 16:42

顶上去

3.Re:问:我通过vb(xmlhttp)提交过来的文件,jsp怎样接收?下面是asp的,那位高人改改 [Re: itking] Copy to clipboard
Posted by: itking
Posted on: 2004-09-07 08:57

怎么回事?每人理?

4.Re:问:我通过vb(xmlhttp)提交过来的文件,jsp怎样接收?下面是asp的,那位高人改改 [Re: itking] Copy to clipboard
Posted by: xml1123
Posted on: 2004-09-20 14:23

通过网页请求是不是显示出xml格式的数据?
request.getInputStream()
通过输入流进行操作,试试。

5.Re:问:我通过vb(xmlhttp)提交过来的文件,jsp怎样接收?下面是asp的,那位高人改改 [Re: itking] Copy to clipboard
Posted by: iqueen
Posted on: 2004-09-27 17:46

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class FileUpload extends HttpServlet {

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<html>");

out.print("File upload success. <a href=\"/jspbook/files/");

out.print("\">Click here to browse through all uploaded ");

out.println("files.</a><br>");

ServletInputStream sis = request.getInputStream();

StringWriter sw = new StringWriter();

int i = sis.read();

for (;i!=-1&&i!='\r';i=sis.read()) {

sw.writeLight Bulb;

}

sis.read(); // ditch '\n'

String delimiter = sw.toString();

int count = 0;

while(true) {

StringWriter h = new StringWriter();

int[] temp = new int[4];

temp[0] = (byte)sis.read();

temp[1] = (byte)sis.read();

temp[2] = (byte)sis.read();

h.write(temp[0]);

h.write(temp[1]);

h.write(temp[2]);

// read header

for (temp[3]=sis.read();temp[3]!=-1;temp[3]=sis.read()) {

if (temp[0] == '\r' &&

temp[1] == '\n' &&

temp[2] == '\r' &&

temp[3] == '\n') {

break;

}

h.write(temp[3]);

temp[0] = temp[1];

temp[1] = temp[2];

temp[2] = temp[3];

}

String header = h.toString();

int startName = header.indexOf("name=\"");

int endName = header.indexOf("\"",startName+6);

if (startName == -1 || endName == -1) {

break;

}

String name = header.substring(startName+6, endName);

if (name.equals("file")) {

startName = header.indexOf("filename=\"");

endName = header.indexOf("\"",startName+10);

String filename =

header.substring(startName+10,endName);

ServletContext sc =

request.getSession().getServletContext();

File file = new File(sc.getRealPath("/files"));

file.mkdirs();

FileOutputStream fos =

new FileOutputStream(

sc.getRealPath("/files")+"/"+filename);

// write whole file to disk

int length = 0;

delimiter = "\r\n"+delimiter;

byte[] body = new byte[delimiter.length()];

for (int j=0;j<body.length;j++) {

body[j] = (byte)sis.read();

}

// check it wasn't a 0 length file

if (!delimiter.equals(new String(body))) {

int e = body.length-1;

i=sis.read();

for (;i!=-1;i=sis.read()) {

fos.write(body[0]);

for (int l=0;l<body.length-1;l++) {

body[l]=body[l+1];

}

body[e] = (byte)i;

if (delimiter.equals(new String(body)))

break;

}

length++;

}

}

fos.flush();

fos.close();

}

if (sis.read() == '-' && sis.read() == '-')

break;

}

}

out.println("</html>");

}

public void doGet(HttpServletRequest request,HttpServletResponse response)

throws IOException, ServletException {

doPost(request, response);

}

}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923