Results 1 to 3 of 3
Thread: multipart usage
- 04-05-2010, 01:00 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
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> <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>   Description<br> <textarea name="data" rows="4" cols="20"></textarea> <h5> (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
- 04-05-2010, 02:57 PM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Please use code tags to post codes, and whats the issue?
Swastik
- 04-06-2010, 03:26 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
Java Mail Multipart Problem
By lowell108 in forum Advanced JavaReplies: 0Last Post: 01-04-2010, 02:36 PM -
Usage of List
By vasavi.singh in forum New To JavaReplies: 0Last Post: 03-12-2009, 02:51 PM -
HashMap usage
By vasavi.singh in forum New To JavaReplies: 4Last Post: 03-05-2009, 04:50 PM -
usage of Hashtable
By venu2807 in forum New To JavaReplies: 4Last Post: 01-27-2009, 03:36 AM -
enctype=multipart/form-data with form data in struts
By vk_satheesh in forum New To JavaReplies: 0Last Post: 09-19-2008, 12:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks