wood burning stoves 2.0*
The moose likes Struts and the fly likes Interceptor make chages which Unknown to us. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Interceptor make chages which Unknown to us." Watch "Interceptor make chages which Unknown to us." New topic
Author

Interceptor make chages which Unknown to us.

suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
But i am trying to upload file from one location and try to save some else location but Interceptor comes into picture and its make
a some changes to Unknown to me.

I was changed this code like,

package com.kogent.action;

import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import bean.Files;

public class FileUploadAction extends ActionSupport implements ServletRequestAware
{
private HttpServletRequest servletRequest;
String systemFilePath = "D:\\suraj";

public String uploadFile()
{
System.out.println("uploadedFileName = " + this.uploadedFileName);
System.out.println("uploadFile = " + this.uploadedFile);

try
{
System.out.println("In try block. \n");
String realPath = servletRequest.getRealPath("/");
System.out.println(" Server path = " + realPath);

File filePath = new File(systemFilePath);
if(!filePath.exists())
{
filePath.mkdir();
System.out.println("Directory Made. \n");
}
File fileToCreate = new File(filePath,this.uploadedFileName);
FileUtils.copyFile(this.uploadedFile,fileToCreate);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e);
addActionError(e.getMessage());
}

return SUCCESS;
}
}


struts.xml

<struts>
<package name="default" extends="tiles-default">
<action name="upload_file" method="uploadFile" class="com.kogent.action.FileUploadAction">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">
image/png,image/gif,image/jpeg,image/pjpeg
</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="error" type="tiles">error.def</result>
<result name="success" type="tiles">success.def</result>
</action>
</struts>




But still isn't working its thrown an Exception like, as well as uploadedFileName and uploadFile it printed an null values.

Exception :-

Jul 15, 2010 12:44:08 PM org.apache.struts2.dispatcher.Dispatcher getSaveDir
INFO: Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir

uploadedFileName = null
uploadFile = null
In try block.


Server path = D:\FileUploading_Tiles\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\FileUploading_Tiles\
java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at com.kogent.action.FileUploadAction.uploadFile(FileUploadAction.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
......................
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
Jul 15, 2010 12:44:08 PM org.apache.struts2.interceptor.FileUploadInterceptor intercept
INFO: Removing file uploadfile D:\FileUploading_Tiles\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\FileUploading_Tiles\upload_239d1afe_129d4f4053b__8000_00000002.tmp
Jul 15, 2010 12:44:08 PM org.apache.struts2.interceptor.FileUploadInterceptor intercept
INFO: Removing file uploadfile D:\FileUploading_Tiles\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\FileUploading_Tiles\upload_239d1afe_129d4f4053b__8000_00000002.tmp


Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Include all the action code, and the JSP (I believe someone asked you this before, no?) or it's impossible to help.
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
But i am trying to upload file from one location and try to save some else location but Interceptor comes into picture and its make
a some changes to Unknown to me.

I was changed this code like,

package com.kogent.action;

import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import bean.Files;

public class FileUploadAction extends ActionSupport implements ServletRequestAware
{
private HttpServletRequest servletRequest;
String systemFilePath = "D:\\suraj";

public String uploadFile()
{
System.out.println("uploadedFileName = " + this.uploadedFileName);
System.out.println("uploadFile = " + this.uploadedFile);

try
{
System.out.println("In try block. \n");
String realPath = servletRequest.getRealPath("/");
System.out.println(" Server path = " + realPath);

File filePath = new File(systemFilePath);
if(!filePath.exists())
{
filePath.mkdir();
System.out.println("Directory Made. \n");
}
File fileToCreate = new File(filePath,this.uploadedFileName);
FileUtils.copyFile(this.uploadedFile,fileToCreate);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e);
addActionError(e.getMessage());
}

return SUCCESS;
}
}


struts.xml

<struts>
<package name="default" extends="tiles-default">
<action name="upload_file" method="uploadFile" class="com.kogent.action.FileUploadAction">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">
image/png,image/gif,image/jpeg,image/pjpeg
</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="error" type="tiles">error.def</result>
<result name="success" type="tiles">success.def</result>
</action>
</struts>




But still isn't working its thrown an Exception like, as well as uploadedFileName and uploadFile it printed an null values.

Exception :-

Jul 15, 2010 12:44:08 PM org.apache.struts2.dispatcher.Dispatcher getSaveDir
INFO: Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir

uploadedFileName = null
uploadFile = null
In try block.


Server path = D:\FileUploading_Tiles\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\FileUploading_Tiles\
java.lang.NullPointerException
at java.io.File.<init>(Unknown Source)
at com.kogent.action.FileUploadAction.uploadFile(FileUploadAction.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
......................
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
Jul 15, 2010 12:44:08 PM org.apache.struts2.interceptor.FileUploadInterceptor intercept
INFO: Removing file uploadfile D:\FileUploading_Tiles\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\FileUploading_Tiles\upload_239d1afe_129d4f4053b__8000_00000002.tmp
Jul 15, 2010 12:44:08 PM org.apache.struts2.interceptor.FileUploadInterceptor intercept
INFO: Removing file uploadfile D:\FileUploading_Tiles\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\FileUploading_Tiles\upload_239d1afe_129d4f4053b__8000_00000002.tmp


Thanks.
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
You can see in normal application which struts.xml extends "struts-default" it defenatelly work.
But; This Will (file upload) interceptor work in tiles concepts ?

you can see above struts.xml file into that i was extends "tiles-default" but
Their was any problem to file upload interceptor it will automatically available predefined interceptor-ref stack ?
according to me its not available due to uploadedFileName and uploadFile getting null if not then
was i should to do it will works into tiles cencepts.





 
wood burning stoves
 
subject: Interceptor make chages which Unknown to us.
 
Similar Threads
Struts2: file upload not working
Unable to store '.xlsx' file on specific path
Eclipse fileupload no longer works
Why NestedServletException?
null values on console