struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <newton.d...@yahoo.com>
Subject RE: File Upload using Struts2
Date Tue, 16 Oct 2007 09:03:32 GMT
--- Rajagopal_Yendluri <Rajagopal_Yendluri@satyam.com>
wrote:
> How can I get the actual file name which I browsed?

http://struts.apache.org/2.x/docs/file-upload-interceptor.html

By providing a method String fileName property in your
action. Note that different browsers may send the
actual filename differently (like not sending the
entire path, just the filename).

d.

> 
> -----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.
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 
=== message truncated ===


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message