Link to home
Start Free TrialLog in
Avatar of Arthur Wang
Arthur WangFlag for United States of America

asked on

how apache access the files uploaded by application server

my apache web server is physically located in different machine from where I host Jboss application server. I use mod_jk to connect them together. when  I previously put apache and Jboss in the same machine, in the struts action class, I specify the absolute path of the folder for uploaded files, then use apache alias to point to the same folder,since they are in the same machine,  apache can easily find the file uploaded, but now I seperate apache web server and jboss application server into different machines,  I find the file is uploaded to the Jboss machine physically only, how can I let the apache access the uploaded file in different machine? if can not, can storage server do this?

in my struts action class, ,  can I set the path to specific machine? such as provide path with ip address of specific machine :  
 
//xxx.xxx.xxx.xxx/c://upload_folder/

instead of

c://upload_folder/  

if I can set up a network drive, how can I do that?

thanks for any comment,  I need solution in production.
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arthur Wang

ASKER

does this means that the file have to be saved in the jboss machine? even not be able to be saved in any network drive or any NAS(network attached storge server?)
No, it would just need to be accessable from the JBoss machine (as that is where tomcat is running)

So long as the NAS was accessable via a network share, or mount point, it should be ok...
I'm using Swing to Browse the File. And I need to Upload the file into the Server in the particular location.
By using JSP I can upload the file easily using common-upload jar. But The client doent need JSP to be used. I need Java code by which the file can be upload. See in my class there is no HTTP request and Response. Please let me know how to create a servlet and get the request. Please give me detail code.


See I'm not using JSP to get the file. I'm using java Swing

In the below code from where i'll get the request.

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
 
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
 
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.servlet.*;
 
/**
 * Class for storing the uploaded files.
 * 
 * @author JavaAtWork
 */
public class UploadServlet extends HttpServlet{
 
	public void doGet(HttpServletRequest request) throws ServletException, IOException { 
 
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);
		if (!isMultipart) {
		} else {
			FileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			upload.setSizeMax(1000000000);
			List items = null;
			try {
				items = upload.parseRequest(request);
			} catch (FileUploadException e) {
				e.printStackTrace();
			}
			Iterator itr = items.iterator();
			while (itr.hasNext()) {
				FileItem item = (FileItem) itr.next();
				if (item != null){
					if (item.isFormField()) {
					} else {
						try {
							String itemName = item.getName();
							String location = "/export/home/tcradm/CandEMig/";
						   	int index = itemName.lastIndexOf("\\")+1;
						   	String fileName = itemName.substring(index, itemName.length());
						   	System.out.println("File Name: "+fileName);							   				   						   	
							GenericServlet config = null;
							File savedFile = new File(location+fileName);
							item.write(savedFile);  				
							System.out.println("<tr><td><b>Your file has been saved at the loaction:"+location+fileName);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}
			}
		}
	}	
}

Open in new window