The CS software sends data to the BS-side JSP page. jsp accepts the data and saves it as a file.
Below is the data sent by CSHARPCode:
using (filestream = new filestream (file. fullname, filemode. open, fileaccess. read) {long Len = filestream. length; byte [] imgbytes = new byte [filestream. length]; filestream. read (imgbytes, 0, (INT) filestream. length); WebClient client = new WebClient (); string guid = guid. newguid (). tostring ("N"); string filesavepath = getfilesavepath (); // The path format is http: // 192.168. 0.201: 7001/affixfile/upload. jsp? Newfilename=aaa.jpg & filepath = c: \ SMZ \ 01 \ string posturl = string. format (@ "{01_1_12.16.jpg & filepath = {2} \ 0", appconfig. getvalue ("savephotourl"), guid, filesavepath); byte [] uploadbyte = client. uploaddata (posturl, "Post", imgbytes) ;}
The following is the code of the JSP terminal receiving data page:
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" %> <% @ page import = "Java. util. *, Java. io. *, Com. itsv. CMS. base. writer. publishfilewriter; "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML lang = "true">
If the Asp.net page accepts data, you can use the following method:
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. io; namespace webckeditor {// <summary> // abstract description of imgupload /// </Summary> public class imgupload: ihttphandler {public void processrequest (httpcontext context) {// context. response. contenttype = "text/plain"; // context. response. write ("Hello World"); // app. log. info (context. request. URL. tostring (); // get the upload Data Stream string filenamestr = datetime. now. tostring ("yyyy-mm-ddhhmmssfff"); // context. request. querystring ["FILENAME"]; stream sr = context. request. inputstream; string newfilename = context. request. querystring ["newfilename"]; try {string filename = filenamestr; byte [] buffer = new byte [4096]; int bytesread = 0; // write the current data stream to the string targetpath = context in the clientbin folder on the server side. server. mappath ("~ /Uploadimg/"+ newfilename); Using (filestream FS = file. create (targetpath, 4096) {While (bytesread = sr. read (buffer, 0, buffer. length)> 0) {// write information to the file FS. write (buffer, 0, bytesread);} context. response. contenttype = "text/plain"; context. response. write ("uploaded successfully" + newfilename);} catch (exception e) {context. response. contenttype = "text/plain"; context. response. write ("Upload Failed, error message:" + E. message); // app. log. info (E. message);} finally {Sr. dispose () ;}} public bool isreusable {get {return false ;}}}}