Results 1 to 3 of 3

Thread: multipart usage

  1. #1
    shreya is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default multipart usage

    servlet
    Java Code:
    public class uploading extends HttpServlet {
         static Connection con;
        PreparedStatement ps;
       java.sql.ResultSet rs;
        static Statement stmt;
        static boolean status;
        String aa[];
    
    
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
           System.out.println("Inside servlet uploading doPost");
           String path="C:/Documents and Settings/221584/Desktop/upload";
           //   String path2="C:/Documents and Settings/221584/Desktop/upload/images";
           //System.out.println("The path to be saved is"+path);
              ;
           MultipartRequest uploadFile=new MultipartRequest(request,path);
           //MultipartRequest uploadFile1=new MultipartRequest(request,path2);
          PrintWriter out = response.getWriter();
          Enumeration file = uploadFile.getFileNames();
          while(file.hasMoreElements()) {
          String filepath = (String)file.nextElement();
          out.println("<TR><TD>" + filepath + "\n<TD>");
          String[] pathvalues = request.getParameterValues(filepath);
          System.out.println(pathvalues[0]);
     System.out.println(pathvalues[1]);
     // String file[]=uploadFile.getFileNames("pathname");
          String aa[]=uploadFile.getParameterValues("data");
    
                    System.out.println(aa[0]);
      System.out.println(aa[1]);
    				String query="insert into AJ412_upload(technology,desc,path,image) values('"+aa[0]+"','"+aa[1]+"','"+pathvalues[0]+"','"+pathvalues[1]+"')";
    		database_upload obj=new database_upload();
    		out.println("query is"+ query);
    		obj.DBConnect(query);
    
    
    
        }
        }
    }
    
    -----------------------jsp---------------------------------
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
       <%@ page import="java.sql.*"%>
    <%@ page import="ocrf.dbconnectivity" %>
    <%@page import="ocrf.populateOptions" %>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Uploade Page</title>
        </head>
    <BODY ONLOAD="loadOptions()"><style type="text/css">
    {text-align:right;}<a href="http://index.jsp" target="logout.jsp">Logout</a>
    </style>
    <form action="uploading" method="post" enctype="multipart/form-data">
    <script type="text/javascript">
                function loadOptions()
                {
                   
                  <%
    String query="";
    String[] temp=null;
    String var=null;
    populateOptions obj=new populateOptions();
    var=obj.getTechValues();
    temp=var.split(":");
    System.out.println("TechValues"+var+" length : "+temp.length);
    for(int i=0;i<temp.length;i++)
    {
    System.out.println("Loop Option Values : "+temp[i]);
    %>
    
            document.getElementById("tech").options[<%=i%>]=new Option("<%=temp[i]%>","<%=i%>");
           
    <%}%>
    
    
                }
    
    
     </script>
    
    <TABLE>
      <TBODY>
      <TR>
        <TD colSpan=20><b><i>WELCOME!!</i></b></TD>
        <TD width=700></TD>
        <TD><A href="http://localhost:8084/MFRP1/url">LOG OFF</A></TD>
      <TR></TR></TBODY>
    </TABLE><BR>
    
         <h3><center><H1><u>UPLOAD COMPONENTS</u></H1>
         </center></h3>
    
                 <table cellspacing = "5" cellpadding="10">
                        <tr>
                            <td>Technology :</td>
                            <td><select id="tech" name="data"  style="width:50%">
                              
                                </select></td>
                        <tr>
                            <td>Choose a file:</td>
                            <a href="C:\Documents and Settings\221584\Desktop\upload">Image</a>
      <br />
                            <td><input type="file" name="pathname" id="upload" /></td>
    
    
    
                        </tr>
                      </table>
                      <table cellspacing = "5" cellpadding="10">
                        <tr>
                            <td>Choose an image:</td>
                          <td>&nbsp;<input type="file" name="pathname" value="Imagename"id="upload1" width="25" />
                          <a href="C:\Documents and Settings\221584\Desktop\upload\"></a>
      <br />
                            </td>
    
                     </tr>
                     </table>
                     &nbsp;&nbsp;&nbsp Description<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                     <textarea name="data" rows="4" cols="20"></textarea>
                     <h5>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(max 250 Characters)</h5>
    
    
                     
                     <center>
                     <table cellspacing = "10" cellpadding="10">
                    <tr>
                            <td>
                                <input type="Submit" value="Submit"/>
                            </td>
                            <td>
                                <input type="Submit" value="Reset" />
                            </td>
                            <td>
                            <input type="Submit" value="Back"/>
                            </td>
                             
                        </tr>
                        </table>
                </center>
                                
    </form>
              </BODY>
    </html>
    Last edited by Eranga; 04-06-2010 at 03:18 AM. Reason: added code tags

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Please use code tags to post codes, and whats the issue?
    Swastik

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Please use code tags next time when you are posting codes here again. Unformated codes are really hard to read. If you don't know how to do that check on my signature, you can find a FAQ page about code tags.

    And also please explain your question more clearly. I don't think that anyone wants to run your code and fix the errors.

Similar Threads

  1. Java Mail Multipart Problem
    By lowell108 in forum Advanced Java
    Replies: 0
    Last Post: 01-04-2010, 02:36 PM
  2. Usage of List
    By vasavi.singh in forum New To Java
    Replies: 0
    Last Post: 03-12-2009, 02:51 PM
  3. HashMap usage
    By vasavi.singh in forum New To Java
    Replies: 4
    Last Post: 03-05-2009, 04:50 PM
  4. usage of Hashtable
    By venu2807 in forum New To Java
    Replies: 4
    Last Post: 01-27-2009, 03:36 AM
  5. enctype=multipart/form-data with form data in struts
    By vk_satheesh in forum New To Java
    Replies: 0
    Last Post: 09-19-2008, 12:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •