Please help me,i was tried to find answer on google for whole week but no luck for me. Nothing work with me at all, and this is my problem, i will really appriciate your help.
i want to upload a picture on my host and i used code like this and it worked fine on localhost but not in my real Hosting. This is my code:
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
}
else {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
params.put(item.getFieldName(), item.getString());
} else {
try {
String itemName = item.getName();
filename = rdhash.randomHash() + itemName.substring(
itemName.lastIndexOf("\\") + 1);
String realPath = getServletContext().getRealPath("/")
+ "banner\\" + filename;
out.println(realPath);
File savedFile = new File(realPath);
item.write(savedFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
as i said, it can not work on my real hosting. I was try to find why it doesn't work and i find out that it can not get the upload path, it likely can't get the upload path because the out.println() code show me like this:
null\banner\[my file name].jpg
but when i try on my localhost it is show whole path to my project like:
C:\[myproject folder]\banner\[my file name].jpg
i don't know why it can't get the realpath on my host. Please help me, my mind is blowing now. My hosting server is Tomcat 7 bros.
----------------------------update--------------------- this is part in my server.xml content.
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access" suffix=".log" rotatable="false"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="[myhost].com" appBase="/Homedata/[hostname]/public_html" unpackWARs="true" deployXML="false">
<Alias>www.[hostname].com</Alias>
<Context path="" reloadable="true" docBase="/Homedata/[hostname]/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/easy/share/easy-tomcat7/webapps/manager">
</Context>
</Host>