2013年11月14日星期四

tomcat server in the photos how to save it to your hard drive ??

Find great God explain ah. Jiqiu Jiqiu ! ! ! ! ! !
------ Solution ---------------------------------------- ----

  
  
I said my aim is to keep the photo myeclipse workspace . . Regardless copy okay .  
learn about it yourself http://blog.sina.com.cn/s/blog_60afee6e010136dc.html
------ Solution ---------------------------------------- ----
protected Map parseMultipart (HttpServletRequest request) {
Map map = new HashMap ();
RequestContext ctx = new ServletRequestContext ((HttpServletRequest) request);
if (! FileUpload.isMultipartContent (ctx))
return map;
try {
DiskFileItemFactory factory = new DiskFileItemFactory ();
ServletFileUpload upload = new ServletFileUpload (factory);
upload.setSizeMax (1024 * 1024 * 5) ;/ / set the file is limited to 5M
List items = upload.parseRequest ((HttpServletRequest) request);
if (items! = null) {
Map > tmp = new HashMap > ();
for (FileItem item: items) {
Object value = item.isFormField ()? item.getString ("UTF-8"): item;
if (! tmp.containsKey (item.getFieldName ())) {
List values ​​= new ArrayList ();
tmp.put (item.getFieldName (), values);
}
tmp.get (item.getFieldName ()). add (value);
}
if (tmp.size ()> 0) {
for (String key: tmp.keySet ()) {
List values ​​= tmp.get (key);
if (values.size () == 1) {
map.put (key, values.get (0));
} else {
map.put (key, values.toArray ());
}
}
}
}
} catch (Exception e) {
logger.error (e);
}
return map;
}

------ Solution ------------------------------------ --------
public void fileUpload2 () {

String result = "OK";
/ / upload.setSizeMax (1024 * 1024 * 5);
HttpServletRequest request = ServletActionContext
. getRequest ();
String appName = request.getContextPath ();
/ / upload folder path
String path = ".. / webapps" + appName + "/ files /";
/ / Return the network address upload pictures
String basePath = request.getScheme () + ":/ /" + request.getServerName ()
+ ":" + request.getServerPort () + appName + "/" + "files /";
String httpurl = "";
try {



String fname = this.getFileStream2FileName ();
/ / System.out.println (fname);
/ / System.out.println ("$ $ $ $ $ $ $ $ $ $ $ $ $ $ $" + fileStream2.length);
String [] fnameList = fname.split (",");
for (int i = 0; i String path1 = path + fnameList [i]. trim ();
String onrepath = basePath + fnameList [i]. trim ();
httpurl = httpurl + onrepath + ",";
File f = new File (path1);
if (! f.getParentFile (). exists ())
f.getParentFile (). mkdirs ();
f.createNewFile ();
FileOutputStream fi = new FileOutputStream (f);
InputStream in = new FileInputStream (fileStream2 [i]);;
byte buffer [] = new byte [8192];
int bytesRead = 0;
while ((bytesRead = in.read (buffer, 0, 8192))! = -1) {
fi.write (buffer, 0, bytesRead);
}
in.close ();
fi.close ();
}

} catch (Exception e) {
e.printStackTrace ();
result = "ERROR: Exception, please contact the administrator ! ' ;
}
HttpServletResponse res = ServletActionContext.getResponse ();
if ("OK". equals (result)) {
putJsondata (httpurl, res);
/ / System.out.println ("333333333 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" + httpurl);
} else {

putJsondata (result, res);
}


}
------ For reference only --------------------------------- ------
copy and paste can do
------ For reference only --------------------- ------------------
you want to save the photos on a remote tomcat server to the local computer ?
------ For reference only -------------------------------------- -


should be like this !
------ For reference only -------------------------------------- -
direct download ah, write a preservation method
------ For reference only ------------------------- --------------
can understand a little what ?
------ For reference only -------------------------------------- -
in the end is a database or server hard disk ?
hard drive, if you can log in to the server, directly copy it.
database to write a program to read out the two binary images written to disk
------ For reference only ----------------- ----------------------


not ah.
------ For reference only -------------------------------------- -


binary program how to write ? ? ?
------ For reference only -------------------------------------- -
then be packaged download function chant much a thing.
------ For reference only -------------------------------------- -



say . I now have a web page can transfer photos . I now pass to the tomcat server in the. But did not save it to the hard disk . This so-called hard disk is myeclipse workspace.
------ For reference only -------------------------------------- -



not mean that. Made it so simple as .
------ For reference only -------------------------------------- -

  
  
not mean that. Made it so simple as .  
Then you 'd like to talk about how you want the functionality , you said , I briefly describe than okay
------ For reference only ---- -----------------------------------

    
    
not mean that. Made it so simple as .          
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I  


say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !
------ For reference only -------------------------------------- -
you did not make it clear which pictures exist , there is a direct binary database , such as mysql mongodb so on. This write process.
If myeclipse working space, which means that on the hard disk . Copy it, boy
------ For reference only ---------------------------------- -----



I said my aim is to keep the photo myeclipse workspace . . Regardless copy okay .
------ For reference only -------------------------------------- -

    
    
I said my aim is to keep the photo myeclipse workspace . . Regardless copy okay .          
learn about it yourself    http://blog.sina.com.cn/s/blog_60afee6e010136dc.html  

moderator . You send these I have achieved . . I really do not understand ....

------ For reference only ---------------------------------- -----

      
      
I said my aim is to keep the photo myeclipse workspace . . Regardless copy okay .                
learn about it yourself      http://blog.sina.com.cn/s/blog_60afee6e010136dc.html          
  
moderator . You send these I have achieved . . I really do not understand ....   
 

I do not understand why you want it. . . .
------ For reference only -------------------------------------- -
realize you just use your program reads the database ah, read out the written your myeclipse workspace directory is not finished ? ?
------ For reference only -------------------------------------- -

        
        
I said my aim is to keep the photo myeclipse workspace . . Regardless copy okay .                      
learn about it yourself        http://blog.sina.com.cn/s/blog_60afee6e010136dc.html                
    
moderator . You send these I have achieved . . I really do not understand ....     
         
  
I do not understand why you want it. . . .  


I've been working space in the tomcat saved photos. But now I want to transfer photos from your workspace tomcat myeclipse workspace to go ah. How broken ? ? ?
------ For reference only -------------------------------------- -



I would say I wrote it with sevlet
------ For reference only ------------------------- --------------

      
      
not mean that. Made it so simple as .                
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I          
  
  
say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !   server will not do one off I have not encountered this situation ,
------ For reference only -------------- -------------------------

        
        
not mean that. Made it so simple as .                      
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I                
    
    
say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !        server will not do one off I have not encountered such a situation,  


you have done this feature baa ? Seeking the source code reference ! !
------ For reference only -------------------------------------- -

          
          
not mean that. Made it so simple as .                            
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I                      
      
      
say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !            server will not do one off I have not encountered such a situation,          
  
  
you have done this feature baa ? Seeking the source code reference ! !  

Just upload to the server, not the picture is not , unless you are in myeclipse redeploy each time the project started , only not to .
------ For reference only -------------------------------------- -

            
            
not mean that. Made it so simple as .                                  
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I                            
        
        
say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !                server will not do one off I have not encountered such a situation,                
    
    
you have done this feature baa ? Seeking the source code reference ! !          
  
Just upload to the server, not the picture is not , unless you are in myeclipse redeploy each time the project started , only not to .  


seeking the source code. Great God
------ For reference only ----------------------------------- ----

              
              
not mean that. Made it so simple as .                                        
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I                                  
          
          
say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !                    server will not do one off I have not encountered such a situation,                      
      
      
you have done this feature baa ? Seeking the source code reference ! !                
    
Just upload to the server, not the picture is not , unless you are in myeclipse redeploy each time the project started , only not to .          
  
  
seeking the source code. Great God   what code to upload or download ? it does not say how to speak all
------ For reference only ---------------------------- -----------

                
                
not mean that. Made it so simple as .                                              
Then you 'd like to talk about how you want the functionality , you said , describing a simple right than I                                        
            
            
say . A page can now transfer photos to achieve the function , this picture is temporarily stored on a server inside . Server a close , the picture is gone . What I mean is how to save photos to myeclipse workspace inside ! ! ! ! !                        server will not do one off I have not encountered such a situation,                            
        
        
you have done this feature baa ? Seeking the source code reference ! !                      
      
Just upload to the server, not the picture is not , unless you are in myeclipse redeploy each time the project started , only not to .                
    
    
seeking the source code. Great God        what code to upload or download ? it does not say how to speak all  


upload . Uploaded . .
------ For reference only -------------------------------------- -
own research it in two ways.
------ For reference only -------------------------------------- -




Thank god . I'll give you points ! ! !
------ For reference only -------------------------------------- -
landlord mean there is a JSP page upload files / images that are then saved to the number of data ( stored in your database should be the picture url), and then displays the time as long as you can read the url display pictures, but these pictures will be saved to the tomcat deployment project , each restart service, there would be no picture . That URL will not work and then read the display picture. Landlord I have done such a thing before , but there is no good solution . I was directly in the data inventory binaries.
------ For reference only -------------------------------------- -
String path = servletContext.getRealPath ("/ photo") + "\ \";
File file = new File (path);
if (! file.exists ()) {
if (file.mkdirs ()) {
log.info (" Create Folder successfully ! " ) ;
}
}
in the project to create a folder , and then write files
------ For reference only --------------------- ------------------
I tell you quite speechless
you say is the page to submit pictures saved to the server and then chant
busted those useless engage others dizzy ah
you use servlet then I'll give you the code

//接收页面传过来的文件
 private File attached;
 private String attachedFileName;
 private String attachedContentType;
 
 FileUtil.move(attachedInfo.getAttached(), url+fileName);

you can get the file will be able to save the file to any directory on your server specific method Baidu click on the line
------ For reference only -------- -------------------------------
simply write the next you should know what I mean, right save file method Baidu, a lot of the file with the file name with path pass in the past wanted to save what you saved the situation which is estimated Road King Biography wrong
As you said tomcat directory entry is not gone shut every time you delete an item and then re-deploy ah ?
tomcat directory you saved on the hard disk that is
------ For reference only ---------------------------------------
landlord , Hello !
Your question now is : You put your application deployed to tomcat server, to achieve a picture upload function ,
time picture has been uploaded to your server applications deployed a directory.
If you redeploy , it will lead to missing image is not it. This situation is normal.
I talk about my solution to it. Before encountered such a problem . See if we can help you.
1. every upload pictures are copied to your myeclipse workspace
what your workspace will have the picture , each deployment , pictures will be copied to the tomcat server inside .
( If you can copy images directly on the tomcat server words )

2. configure the virtual directory ( Baidu about it , I used this method to achieve ) .


没有评论:

发表评论