naveen chedella

Greenhorn
+ Follow
since Dec 05, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by naveen chedella

I have removed unneccessary HTML tags and still it does not work....

Modeified Input.jsp

Input.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<html:form action="/LoadPowerForecast" method="post" enctype="multipart/form-data">


<html:file property="theFile"/></td>


<html:submit property="method"><bean:message key="LoadPower.Load"/></html:submit>

</html:form>

12 years ago
I am using a Form File for file Upload in my application.In this i am getting a strange problem.

Input.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:form action="/LoadPowerForecast" method="post" enctype="multipart/form-data"> </html:form>
External Power Forecast Data File : <html:file property="theFile"/></[/b]td>
   
<html:submit property="method"><bean:message key="LoadPower.Load"/></html:submit>


Form Bean:
package com.ngt.wpfs.forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;


public class LoadPowerForm extends ActionForm {
private FormFile theFile;
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}

public FormFile getTheFile() {
return theFile;
}
}

By clicking "Load" submit button,all the data is submitted and then processing is done in Action Class and the action class will forward back it input.jsp. But while displaying input.jsp from action class the file name which i have selected earlier is not showing in input.jsp .




12 years ago
Is there any way of uploading all the files in a directory to the server? For my requirement,user enters the directory name from the browser and i need to upload all the files to server and than process all the files.I am using struts1.1 . FormFile uploads only one file and i want to upload all the files from the directory.
12 years ago
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
12 years ago
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");
}
}
12 years ago
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.


12 years ago
<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...

12 years ago
Hi,
can any one please tell me how to split the data in to equal size Chunks.
13 years ago