tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Srofe, Douglas (c)" <Douglas.Sr...@NielsenMedia.com>
Subject RE: How to Upload a File Using JSP?.(Snippest of code needed)
Date Tue, 10 Aug 2004 13:55:18 GMT
Go to http://jakarta.apache.org/commons. There is a file upload component. 

-----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.
 
=============================
 
 
<%@ page    language="java" contentType="text/html" %> 
<%@ page    import = "java.io.*" %> 
<%@ page    import = "java.lang.*" %> 
<%@ page    import = "java.sql.*" %> 
<%@ page  import = "org.apache.turbine.util.RunData" %> <%@ page  import =
"org.apache.turbine.util.Log" %> 
<%@ page    import = "javax.servlet.http.*" %> 
<%@ taglib  uri='/WEB-INF/templates/jsp/tld/template.tld' 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","ro
ot","");
       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+"<br>"); 
               
               
               out.println( "<HTML><HEAD><TITLE>Confirmation-Added Grid
Nodes</TITLE></HEAD>" );
             out.println( "<BODY bgcolor=blue text=white><br>");
             out.println( "<h2 align=center><FONT face=Verdana,Geneva,Arial
color=white size=4><b>ADD JOBS</b></font></h2>");
             out.println("<FONT face=Verdana,Geneva,Arial  size=1>");

        
             out.println( "<table align=center><br>");
             out.println("<tr><td><b>The Details Belongs to
Job:&nbsp;</td><td></td><td>"+cpu1+" &nbsp;is added to the
Database..!.</b></td></tr><br>");
             
             out.println("</table>");
             out.println("</font>");
             out.println("</BODY>");
             out.println("</HTML>");
  
       st.close();
       con.close();
        
     
      }else
      {
  %>
   <body bgcolor=blue text=white>
   <form action="SubmitJobs.jsp" enctype="multipart/form-data"
method="POST"><br><br>
   <FONT face=Verdana,Geneva,Arial color=white size=1>
   <br>
   <h2 align="center"><FONT face=Verdana,Geneva,Arial color=white
size=4><b>SUBMIT JOBS</b></font></h2>
   <br>
   <center>
   
   <table   align="center" >
        <tr>
             <td><b><FONT face=Verdana,Geneva,Arial color=white
size=2>CPU:<sup>*</sup></FONT></b></td>
             <td>&nbsp;</td><td>&nbsp;</td> 
             <td><input type="text" name="cpu" value="" size="20"></td>
            </tr>
      
        <tr>
            <td><b><FONT face=Verdana,Geneva,Arial color=white
size=2>Architecture:<sup>*</sup></FONT></b></td>
            <td>&nbsp;</td><td>&nbsp;</td> 
         <td><input type="text" name="architecture" value="" size="20"></td>
        </tr>
        
    <tr>
            <td><b><FONT face=Verdana,Geneva,Arial color=white
size=2>Execute PBS File:<sup>*</sup></FONT></b></td>
            <td>&nbsp;</td><td>&nbsp;</td> 
            <td><INPUT TYPE="file" NAME="fileToUpload"></td</td>
    </tr>
        
        
                 
      
         
   </table>
   <br><br>
   
   <input type="submit" value="Submit" />
   
   
   </center>
   </font>
   </form>
   </body>   
   
      
<%
   } //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


Mime
View raw message