struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Raghuveer Rawat" <raghuveer.ra...@gmail.com>
Subject Re: File Upload using Struts2
Date Tue, 16 Oct 2007 15:20:00 GMT
I already have enctype="multipart/form-data"

I can see below errors in log.. Looks like request is getting terminated
befor

Content-Type not allowed: myPhoto
"upload_7ddb4d8f_115a947dc12__8000_00000000.tmp" image/pjpeg
java.lang.NullPointerException: Source must not be null

Looks like request is getting complete before it reaches to FileUpload.
How to make this request available to FileUpload?

Thanks
Raghu

On 10/16/07, Rajagopal_Yendluri <Rajagopal_Yendluri@satyam.com> wrote:
>
> Hi Raghu,
>
>
>
>    There should be no problem with the configuration, you have to set
> the "enctype"
>
>
>
> Here is my code:
>
>
>
> JSP
>
>
>
>
>
> <s:form action="Login" enctype="multipart/form-data">
>
>
>
> <s:file name="myFile" label="UploadFile"/>
>
>
>
> Action
>
>
>
>            File f = new File("C:\\Tomcat 6.0\\abcd.jpeg");
>
>            FileUtils.copyFile(getMyFile(), f);
>
>
>
>
>
> Find out where is the problem in your code, if not able to please post
> the code.
>
>
>
> Regards,
>
> Rajagopal Y
>
> HCU-Consulting & Enterprise Solutions.
>
> Phone: (C) +91-9886876114 / (W) 6658 3685.
>
>
>
>
>
> -----Original Message-----
> From: Raghuveer Rawat [mailto:raghuveer.rawat@gmail.com]
> Sent: Tuesday, October 16, 2007 10:31 AM
> To: Struts Users Mailing List
> Subject: Re: File Upload using Struts2
>
>
>
> Thanks Dave for reply..
>
> I have no clue what is happening...I can see below statement in log..
>
>
>
> Content-Type not allowed: myPhoto
>
> "upload_460c03b6_115a6ef087d__8000_00000000.tmp" image/jpeg
>
>
>
> I have configured filters like below in web.xml.. I don't have context
>
> clean-up filter. Where should I place this filter?
>
>
>
> <filter>
>
>        <filter-name>openSessionInViewFilter</filter-name>
>
>        <filter-class>
>
> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
>
> </filter-class>
>
>    </filter>
>
>
>
>    <filter>
>
>        <filter-name>filterDispatcher</filter-name>
>
>        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher
>
> </filter-class>
>
>    </filter>
>
>
>
>    <filter-mapping>
>
>        <filter-name>openSessionInViewFilter</filter-name>
>
>        <url-pattern>/*</url-pattern>
>
>    </filter-mapping>
>
>
>
>    <filter-mapping>
>
>        <filter-name>filterDispatcher</filter-name>
>
>        <url-pattern>/*</url-pattern>
>
>    </filter-mapping>
>
>
>
>    <listener>
>
>        <listener-class>
>
> org.springframework.web.context.ContextLoaderListener</listener-class>
>
>    </listener>
>
>
>
>    <listener>
>
>        <listener-class>org.apache.struts2.tiles.StrutsTilesListener
>
> </listener-class>
>
>    </listener>
>
>
>
> Thanks
>
> Raghu
>
>
>
>
>
>
>
> On 10/15/07, Dave Newton <newton.dave@yahoo.com> wrote:
>
> >
>
> > In general it's a good idea to include things like
>
> > what is actually happening: what symptoms (besides
>
> > "the file isn't uploading" :) are there? Is there
>
> > anything in the logs?
>
> >
>
> > Are you including the context cleanup filter in your
>
> > web.xml?
>
> >
>
> > d.
>
> >
>
> > --- Raghuveer Rawat <raghuveer.rawat@gmail.com> wrote:
>
> >
>
> > > Hi, I am trying to upload a jpg image using Struts2
>
> > > but no luck till now. It
>
> > > will be great if someone could help me in moving
>
> > > further.
>
> > >
>
> > > I am using Struts 2.0.8 and i have
>
> > > commons-fileupload-1.2.jar and
>
> > > commons-io-1.3.2.jar in classpath
>
> > >
>
> > > My code looks like below.
>
> > >
>
> > > MyPhoto.jsp
>
> > >
>
> > > <s:form method="post" action="myPhotoUpload"
>
> > > enctype="multipart/form-data">
>
> > > <s:file name="myPhoto" cssClass="textbox1"
>
> > > accept="image/*" />
>
> > > <s:submit name="method:upload" cssClass="btn"
>
> > > value="Upload" />
>
> > > </s:form>
>
> > >
>
> > > Action class: MyPhotoUploadAction.java
>
> > >
>
> > > private File myPhoto;//The actual file
>
> > >     private String myPhotoContentType; //The content
>
> > > type of the file
>
> > >     private String myPhotoFileName; //The uploaded
>
> > > file name
>
> > >
>
> > >  public File getMyPhoto() {
>
> > >         return myPhoto;
>
> > >       }
>
> > >
>
> > >       public void setMyPhoto(File myPhoto) {
>
> > >         System.out.println("Inside setMyPhoto");
>
> > >         this.myPhoto = myPhoto;
>
> > >       }
>
> > >
>
> > >       public String getMyPhotoContentType() {
>
> > >         return myPhotoContentType;
>
> > >       }
>
> > >
>
> > >       public void setMyPhotoContentType(String
>
> > > myPhotoContentType) {
>
> > >         System.out.println("Inside
>
> > > setMyPhotoContentType");
>
> > >         this.myPhotoContentType =
>
> > > myPhotoContentType;
>
> > >       }
>
> > >
>
> > >       public String getMyPhotoFileName() {
>
> > >           System.out.println("Inside
>
> > > getMyPhotoFileName:"+myPhotoFileName);
>
> > >         return myPhotoFileName;
>
> > >       }
>
> > >
>
> > >       public void setMyPhotoFileName(String
>
> > > myPhotoFileName) {
>
> > >         System.out.println("Inside
>
> > > setMyPhotoFileName:"+myPhotoFileName);
>
> > >         this.myPhotoFileName = myPhotoFileName;
>
> > >       }
>
> > >
>
> > >       public String upload() {
>
> > >          try{
>
> > >             System.out.println("Inside Upload");
>
> > >             File destDir = new
>
> > > File("images/member");
>
> > >              System.out.println("File
>
> > > Name:"+this.getMyPhotoFileName());
>
> > >              System.out.println("File
>
> > > ContentType:"+this.getMyPhotoContentType());
>
> > >
>
> > > FileUtils.copyFileToDirectory(getMyPhoto(),
>
> > > destDir);
>
> > >              return SUCCESS; // redirect to welcome
>
> > > page.
>
> > >          }catch(Exception exp){
>
> > >              LOG.error("File Upload Error:"+ exp);
>
> > >              this.addActionError("File Upload
>
> > > Error:"+ exp);
>
> > >              return ERROR;
>
> > >          }
>
> > >       }
>
> > >
>
> >
>
> >
>
> > ---------------------------------------------------------------------
>
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>
> > For additional commands, e-mail: user-help@struts.apache.org
>
> >
>
> >
>
>
>
> DISCLAIMER:
> This email (including any attachments) is intended for the sole use of the
> intended recipient/s and may contain material that is CONFIDENTIAL AND
> PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
> distribution or forwarding of any or all of the contents in this message is
> STRICTLY PROHIBITED. If you are not the intended recipient, please contact
> the sender by email and delete all copies; your cooperation in this regard
> is appreciated.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message