• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem with file separator

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:file> tag works fine when i deployed my application on windows server and client is upload the file from windows machine.It is giving "Unknown Source" once i deployed application on Linux server and client is upload the file from windows machine.

This is something to do with the File Separator.

Even though i changed the File Separator manually from "\" to "/" still its not working and it is giving "File Not Found Exception".

Please Help Me...

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless, TellTheDetails.

No way to help yet.
 
naveen chedella
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my form bean:

public class LoadPowerForm extends ActionForm {
private String strForecastDataFile;

public void setStrForecastDataFile(String strForecastDataFile) {
this.strForecastDataFile = strForecastDataFile;
}
public String getStrForecastDataFile() {
return strForecastDataFile;
}
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
String[] strFileDir = getFileName(getStrForecastDataFile()); //Here i am getting Unknown Source Problem
}

private String[] getFileName(String strAbsoluteFileName) {
String strFileDir[] = new String[2];
try
{
File file = new File(strAbsoluteFileName);
strFileDir[0] = file.getParent();
strFileDir[1] = strAbsoluteFileName.substring(file.getParent().length()+1);
}
catch(Exception e) {
//error message
}
return strFileDir;
}
}

//Here is my Jsp

External Power Forecast Data File : <html:file property="strForecastDataFile" name="LoadPowerForm"/>


This is perfectly worked once i deployed in windows environment but giving the problem only when i deployed in the linux environment.


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

html:file tags should use FormFile fields.
 
naveen chedella
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the FormFile will not give complete User File Path.I tested with the following example.
JSP:
External Power Forecast Data File : <html:file property="theFile" name="StrutsUploadForm "/> // I have Uploaded D:\EXT_FORECAST_DATA_21012009121212 file from the Browser


Form Bean:
public class StrutsUploadForm extends ActionForm
{
private FormFile theFile;
/**
* @return Returns the theFile.
*/
public FormFile getTheFile() {
return theFile;
}
/**
* @param theFile The FormFile to set.
*/
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}
}

Action Class:

package com.ngt.wpfs.actions;

import com.ngt.wpfs.forms.StrutsUploadForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
public class StrutsUploadAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
StrutsUploadForm myForm = (StrutsUploadForm)form;
// Process the FormFile
FormFile myFile = myForm.getTheFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();

System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName); // This gives EXT_FORECAST_DATA_21012009121212.CSV only but i need Directory name and FileName to Retrive the data from the file in corressponding directory





return mapping.findForward("success");
}
}
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was serious--please UseCodeTags.

What would you do with the path from the client machine anyway? Nothing--and some browsers don't even *send* the entire path, so it doesn't matter if you have it or not.
 
naveen chedella
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i needed to read the complete file name to display to the user that he has selected this particular file name and need to read the contents of the file and if the file is not valid then rename the file as Rejected and place it in the directory where client picked the actual file.Thats why i take it as String Property in the form bean and it is perfectly worked when application is deployed in the Windows Machine and client is accessed through browser in Windows machine but this is giving problem when i deployed on the Linux server and client is accessed in Windows machine.

Please help me in this regard.... And this is nothing to do the formfile and this is some thing regarding file separator
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java will work with either separator. If you're dead-set on changing it, go ahead and change it with a replaceAll.

You *CANNOT* rely on the full file path being submitted: that's just a fact of life that has absolutely nothing to do with Struts.
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic