• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interceptor make chages which Unknown to us.

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
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. You can edit your post by using the button.
 
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
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
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.





 
reply
    Bookmark Topic Watch Topic
  • New Topic