throws ServletException, IOException {
DownLoadFile ld = new DownLoadFile ();
sysout (request) ;/ / org.apache.catalina.connector.RequestFacade @ 149f848
ld.setRequests (request);
ld.setResponses (response);
Thread t = new Thread (ld);
t.start ();
}
public void run () {
sysout (request) ;/ / org.apache.catalina.connector.RequestFacade @ 149f848
sysout (requests.getParameter ("applyNo")); / / Question 1 : Can not get at a null pointer
/ / Export main
try {
......
stream.write (readBytes) ;/ / Question 2: Report Connection reset by peer: socket write error
......
} catch {}
finally {
stream.close () ;/ / Question 3 : reported null pointer again
}
}
Scene Description : Analog multi-threaded download files,
Problem Description : 1 reception request can not be used in the run method .
2 time to write the document quoted Connection reset by peer: socket write error, reception no stopped what browser
initial contact with multithreading , trouble you to see it
------ Solution ------------------------- -------------------
that must be a null pointer , requests you have no injection.
------ Solution ---------------------------------------- ----
My feeling is that after the end of your doTest , request should be in the other thread ( is your run ()) then use is problematic . But I do not know how to deal with a servlet container which is , is not this request in the doGet or doPost automatically expire after a ?
------ For reference only -------------------------------------- -
sysout (request) ;/ / this request is how you pass into the ?
------ For reference only -------------------------------------- -
private HttpServletRequest requests;
private void setRequests (HttpServletRequest request) {
this.requests = request;
}
response is so pass
Moreover, the run () method, but also do the following actions:
ServletOutputStream stream = responses.getOutputStream ();
responses.setContentType ("application / octet-stream");
responses.addHeader ("Content-Disposition");
------ For reference only ------------ ---------------------------
landlord seems to DownLoadFile as a servlet. So you want to know your method is now run on a new thread to run , and your doTest method is already over.
------ For reference only -------------------------------------- -
requests.getParameter ("applyNo") the landlord to pay attention to your spelling
------ For reference only -------------------- -------------------
and above sysout (request); is a right
------ For reference only --- ------------------------------------
injection ? What do you mean , get.set it? Elaborate on it? I was white , so many do not understand
That is the run method executes ineffective cough ?
spelling is indeed a problem , it should be
sysout (requests);
sysout (requests.get ...);
------ For reference only ------------------------ ---------------
While still print to request, but the feeling is really unusable
test.
------ For reference only -------------------------------------- -
easier to see and say something :
public void doTest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DownLoadFile ld = new DownLoadFile();
sysout(request);//org.apache.catalina.connector.RequestFacade@149f848
ld.setRequests(request);
ld.setResponses(response);
Thread t = new Thread(ld);
t.start();
}
public void run() {
sysout(request);//org.apache.catalina.connector.RequestFacade@149f848
sysout(requests.getParameter("applyNo")); //问题1:无法获取,报空指针
//导出主程序
try{
......
stream.write(readBytes);//问题2:报Connection reset by peer: socket write error
......
}catch{}
finally {
stream.close();//问题3:再次报空指针
}
}
------ For reference only ----------------------------------- ----
While still print to request, but the feeling is really unusable
test.
Personally, I do not feel so multi -threaded , so if you must use it, but also know how to package and hold request ( a request should have various limitations . Personally, I think this time after doGet or doPost request to sue end ) . Not recommended landlord tried to do in this regard , first lay the foundation of it
没有评论:
发表评论