Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Priyanka Das

Greenhorn
+ Follow
since Mar 01, 2011
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 Priyanka Das



in my HouseHoldinformationAction I am creating a HouseHoldInformationForm.

But error is Village_water_detailsForm

then error is

com.ochre.ewash.hfodetails.web.action.HouseHoldInformationAction.execute(HouseHoldInformationAction.java:38)

Please reply..

Thanks in advance...

9 years ago
This is my new code....




here I am getting NULL.

What I have to write here...



This is my stack trace..
9 years ago
This is my code inside try block....
Below code is working fine...


This is becoming Null..

I have one Question.
I have the file path and file name in database...and file is in server(webapps folder)....
can I get the Filedata through form file....
9 years ago

Joe Ess wrote:

Purnendu Das wrote:



Why are you writing a file on the server? Why is the file's name "C:"??
That is just written.Not using that variable inside try block...........



Do you really have an input file named ""???
No I dont have..



9 years ago
I have uploaded the files.But unable to download ......
Please help ....





Stack Trace


Please Reply..
Thanks in advance...
9 years ago
Why I am getting this error.

my insertUser method is in DAO class
public int insertUser(String strQuery,String fileName,String fileLink)

my insertUser method is in ACTION class
insertUser(strQuery, formFile.getFileName(),path);

data are 1.doc,E:\Project_ewash\apache-tomcat-5.5.28\webapps\ewash\1.doc

in mysql database both fileds are VARCHAR

9 years ago
I have uploaded file in the server.But I am unable to set the directory location for file download.

how I have to do that?

Please reply as soon as possible..

Thanks in advance..


this is uploaded file code...
* @author
*/

public class FileUploadandDownloadAction extends Action {
private static Logger LOG = Logger .getLogger(FileUploadandDownloadAction.class);

public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws Exception{
LOG.info("Inside Action...........");
FileUploadandDownloadForm uploadForm = (FileUploadandDownloadForm)form;

FileOutputStream outputStream = null;
FormFile formFile = null;
try {
formFile = uploadForm.getTheFile();
System.out.println("The formFile is"+formFile);
String path = getServlet().getServletContext().getRealPath("../UploadandDownload")+""+formFile.getFileName();
System.out.println("The Path is"+path);
String contentType = formFile.getContentType();
String fileName = formFile.getFileName();
int fileSize = formFile.getFileSize();
byte[] fileData = formFile.getFileData();
System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName);
System.out.println("File Size: " + fileSize);
System.out.println("File fileData: " + fileData);
outputStream = new FileOutputStream(new File(path));
outputStream.write(formFile.getFileData());
}
finally {
if (outputStream != null) {
outputStream.close();
}
}
System.out.println("The file "+formFile.getFileName()+" is uploaded successfully.");


return mapping.findForward("success");
}
}





9 years ago

Karthik Shiraly wrote:I think problem is here:


You have to use either


or





yaa that was the problem thanks..
9 years ago


This is my action class








this is my form




This is my Jsp page



Please reply as soon as possible.Its urgent

Thanks in advance..

9 years ago

This is my struts-configfilecode
<action
attribute="fileuploadanddownloadForm"
input="/FileUploadandDownload.jsp"
name="fileuploadanddownloadForm"
path="/fileuploadanddownload"
scope="request"
type="com.ochre.ewash.hfodetails.web.form.FileUploadandDownloadAction">
<forward name="success" path="/FileUploadandDownload.jsp"></forward>
</action>




this is my action class
package com.ochre.ewash.hfodetails.web.action;


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

import org.apache.log4j.Logger;
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.util.LabelValueBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.*;
import org.apache.struts.upload.FormFile;
//import org.apache.commons.fileupload.FileItemFactory;

import java.io.*;
import java.util.*;

import com.ochre.ewash.hfodetails.web.form.*;
import com.ochre.ewash.hfodetails.viewhelper.*;





import org.apache.struts.upload.FormFile;
/**
* @author
*/

/**
* Struts File Upload Action Form.
*
*/
public class FileUploadandDownloadAction extends Action {
private static Logger LOG = Logger .getLogger(FileUploadandDownloadAction.class);
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
LOG.info("Inside Action");
FileUploadandDownloadForm myForm = (FileUploadandDownloadForm)form;
// Process the FormFile
FormFile myFile = myForm.getTheFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName);
System.out.println("File Size: " + fileSize);

return mapping.findForward("success");
}
}




Please reply as soon as possible.

Thanks in advance..
9 years ago

Shankar Tanikella wrote:is this what you have in your deployment descriptor? Is it the same? the location




Yaa these code are present in my web.xml file.

Now showing error org.apache.jasper.JasperException: File "/tags/struts-html" not found
9 years ago

Shankar Tanikella wrote:Where do you have your struts-bean.tld, the location




struts-bean.tld is inside WEB-INF
9 years ago
org.apache.jasper.JasperException: File "/tags/struts-bean" not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:160)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:430)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:499)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1558)
org.apache.jasper.compiler.Parser.parse(Parser.java:130)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:245)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:176)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
com.ochre.ewash.core.web.filters.EwashReportFilter.doFilter(EwashReportFilter.java:70)
com.ochre.ewash.core.web.filters.EwashAuthenticationFilter.doFilter(EwashAuthenticationFilter.java:54)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.28 logs.

This is my error stack ? Why I am getting error


<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>

<html:html locale="true">
<head>
<title>Struts File Upload Example</title>
<html:base/>
</head>
<body bgcolor="white">
<html:form action="/fileupload" type="com.ochre.ewash.hfodetails.web.form.StrutsUploadForm" enctype="multipart/form-data">
<table>
<tr>
<td align="center" colspan="2">
<font size="4">Please Enter the Following Details</font>
</tr>

<tr>
<td align="left" colspan="2">
<font color="red"><html:errors/></font>
</tr>



<tr>
<td align="right">
File Name
</td>
<td align="left">
<html:file property="theFile"/>
</td>
</tr>

<tr>
<td align="center" colspan="2">
<html:submit>Upload File</html:submit>
</td>
</tr>
</table>

</html:form>
</body>
</html:html>


This is the JSP code....

Please reply .This is important for my project.

Thanks in advance..
9 years ago