tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allistair Crossley" <Allistair.Cross...@QAS.com>
Subject RE: How to Upload a File Using JSP?.(Snippest of code needed)
Date Tue, 10 Aug 2004 15:21:19 GMT
taken directly from one of our struts actions ...

           // parse the upload using Commons File Upload 1.0
            
            if (FileUpload.isMultipartContent(request)) {
                
                List items = null;

                try {
                    DiskFileUpload upload = new DiskFileUpload();
                    items = upload.parseRequest(request);
                } catch (FileUploadException fuE) {
                    logger.error(user.getUsername() + ": error.checkin.parse; " + fuE.getMessage());
                    errors.add(ActionErrors.GLOBAL_ERROR, 
                        new ActionMessage("error.checkin.parse"));
                    break DO_CHECKIN;
                }

                if (items == null || items.size() == 0) {
                    logger.error(user.getUsername() + ": error.checkin.parse; no items");
                    errors.add(ActionErrors.GLOBAL_ERROR, 
                        new ActionMessage("error.checkin.parse"));
                    break DO_CHECKIN;
                }

                // create a new Checkin wrapper and populate, set in request

                Iterator iterator = items.iterator();
                FileItem primaryFile = null;
                while (iterator.hasNext()) {
                    FileItem item = (FileItem) iterator.next();
                    
                    // capture the actual upload file
                    if (! item.isFormField()) {
                        primaryFile = item;
                    }
                }

Allistair Crossley



> -----Original Message-----
> From: Maruthi [mailto:maruthibabu_2k@yahoo.com]
> Sent: 10 August 2004 14:07
> To: tomcat-user@jakarta.apache.org; Yoav.Shapira@mpi.com
> Subject: RE: How to Upload a File Using JSP?.(Snippest of code needed)
> 
> 
> Hello Yoav,
> Thanks for your reply.I already gone throuth the link.But i 
> am getting some problems as there is no clear example how to proceed.
>  
> A  clear example to upload a file from HTML form would be helpful.
>  
> Thanks for your time,
> Maruthi.
> 
> "Shapira, Yoav" <Yoav.Shapira@mpi.com> wrote:
> Hi,
> Check out the Jakarta Commons Fileupload examples at
> http://jakarta.apache.org/commons/fileupload/.
> 
> Yoav Shapira
> Millennium Research Informatics
> 
> 
> >-----Original Message-----
> >From: Maruthi [mailto:maruthibabu_2k@yahoo.com]
> >Sent: Tuesday, August 10, 2004 5:05 AM
> >To: tomcat-user@jakarta.apache.org
> >Subject: How to Upload a File Using JSP?.(Snippest of code needed)
> >
> >Hello Everybody,
> >I got some problem regarding file uploading using JSP.
> >
> >In my JSP I have a form which contains 2 textboxes and other text box
> for
> >uploading a file.I need to store the information of 2 text
> boxes,uploaded
> >file in the mysql databse.I am looking for the code for uploading a
> file
> >using JSP.
> >
> >Please see below for my code.In this code i need to include the code
> for
> >uploading a file.
> >
> >Any help in this regard would be greatly appreciated..Pl 
> reply in this
> >regard.
> >Thank you,
> >Maruthi.
> >
> >=============================
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >prefix='jetspeed'
> >%>
> >>
> >
> >  >  try
> >  {
> >
> >   if(request.getMethod().equals("POST"))
> >   {
> >        String cpu1=    request.getParameter("cpu");
> >      String architecture1=  request.getParameter("architecture");
> >
> >
> >          Class.forName("org.gjt.mm.mysql.Driver");
> >       Connection
> >con=DriverManager.getConnection("Jdbc:mysql://localhost:3306/
> Thesiswork
> ","r
> >oot","");
> >       Statement st=con.createStatement();
> >
> >          String str="INSERT into submitjobs
> >VALUES('"+cpu1+"','"+architecture1+"','"+file1+"')";
> >            int i=st.executeUpdate(str);
> >               System.out.println("Number of Rows inserted into
> >AddGridNodes Table  is: " +i+"
> ");
> >
> >
> >               out.println( "Confirmation-Added Grid
> >Nodes" );
> >             out.println( "
> ");
> >             out.println( "face=Verdana,Geneva,Arial
> >color=white size=4>ADD JOBS");
> >             out.println("");
> >
> >             out.println( "
> ");
> >             out.println("The Details Belongs to
> >Job: "+cpu1+"  is added to the
> >Database..!.
> ");
> >
> >             out.println("");
> >             out.println("");
> >             out.println("");
> >             out.println("");
> >
> >       st.close();
> >       con.close();
> >
> >
> >      }else
> >      {
> >  %>
> > 
> > >method="POST">
> 
> 
> > 
> > 
> 
> > >size=4>SUBMIT JOBS
> > 
> 
> > 
> >
> > 
> > 
> > >size=2>CPU:*
> >   
> >  [input] 
> > 
> >
> > 
> > >size=2>Architecture:*
> >   
> >  [input] >size="20">
> > 
> >
> > 
> > >size=2>Execute PBS File:*
> >   
> >  [input] 
> > 
> >
> >
> >
> >
> >
> > 
> > 
> 
> 
> >
> >  [input] 
> >
> >
> > 
> > 
> > 
> > 
> >
> >
> >>   } //else
> >   }catch (Exception e)
> >   {
> >      Log.error(e);
> >     return;
> >  }
> >%>
> >
> >
> >
> >
> >---------------------------------
> >Do you Yahoo!?
> >New and Improved Yahoo! Mail - Send 10MB messages!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail - 50x more storage than other providers!
> 


<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> 
-------------------------------------------------------
QAS Ltd.
Developers of QuickAddress Software
<a href="http://www.qas.com">www.qas.com</a>
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT>


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


Mime
View raw message