473,799 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uploading image to server using java servlets

1 New Member
Hey guys.

I am currently working on a project in JSP/Java Servlets, hope this is the right section. So, my problem regards mainly the form through which I will let the user input a file using <input type="file">. I did some research on the internet, telling me that I have two options (on the Servlet side) in order to get the file and store it in a directory on the server, namely O'Reilly's COS MultipartReques t and some other package issued by Apache. Now my problem is that, together with an image upload, I want the user to input other details in the form. I am managing to get the file on the server, however I still cannot get the other details (from textboxes, textareas and drop-down selections) since the form MUST have the enctype="multip art/form-data" property in order for the file upload to work.

Any ideas regarding what I am doing wrong? Or maybe how should I code this task?

Here is the source code:


Expand|Select|Wrap|Line Numbers
  1. <table align="center" cellspacing="1"><form action="AddTrip" enctype="multipart/form-data" method="POST">
  2.                                     <tbody>
  3.                                         <tr>
  4.                                             <td>Trip Name</td>
  5.                                             <td><input type="text" name="Name" value="" /></td>
  6.                                         </tr>
  7.                                         <tr>
  8.                                             <td>Description</td>
  9.                                             <td><textarea name="Description" rows="3" cols="20" value=""></textarea></td>
  10.                                         </tr>
  11.                                         <tr>
  12.                                             <td>Category</td>
  13.                                             <td><select name="Category" size="4">
  14.                                                     <option>Cruise</option>
  15.                                                     <option>Tour</option>
  16.                                                     <option>Park</option>
  17.                                                     <option>History</option>
  18.                                                     <option>Eco-Tourism</option>
  19.                                                 </select></td>
  20.                                         </tr>
  21.                                         <tr>
  22.                                             <td>Price</td>
  23.                                             <td><input type="text" name="Price" value="" /></td>
  24.                                         </tr>
  25.                                         <tr>
  26.                                             <td>Start Date</td>
  27.                                             <td><input name="StartDate" onfocus="showCalendarControl(this);" type="text"></td>
  28.                                         </tr>
  29.                                         <tr>
  30.                                             <td>End Date</td>
  31.                                             <td><input name="EndDate" onfocus="showCalendarControl(this);" type="text"></td>
  32.                                         </tr>
  33.                                         <tr>
  34.                                             <td>Country</td>
  35.                                             <td><select name="Country" size="4">
  36.                                                     <option>Malta</option>
  37.                                                     <option>Gozo</option>
  38.                                                     <option>Comino</option>
  39.                                                     <option>Sicily</option>
  40.                                                     <option>Ibiza</option>
  41.                                                     <option>Greece</option>
  42.                                                 </select></td>
  43.                                         </tr>
  44.                                         <tr>
  45.                                             <td>Places Available</td>
  46.                                             <td><input name="Places" type="text" value=""/></td>
  47.                                         </tr>
  48.                                         <tr>
  49.                                             <td>Upload Picture</td>
  50.                                             <td><input type="file" name="uploaded" accept="image/gif, image/jpeg, image/png, image.jpg"/></td>
  51.                                         </tr>
  52.                                         <tr>
  53.                                             <td colspan="2" align="center"><input type="submit" id="search-submit-long" name="save" value="Submit Trip"></td>
  54.                                         </tr>
  55.                                     </tbody>
  56.                                     </form></table>
  57.  
  58. [Servlet]
  59.  
  60.             String Name = request.getParameter("Name");
  61.             String Description = request.getParameter("Description");
  62.             String Category = request.getParameter("Category");
  63.             String Price = request.getParameter("Price");
  64.             String StartDate = request.getParameter("StartDate");
  65.             String EndDate = request.getParameter("EndDate");
  66.             String Country = request.getParameter("Country");
  67.             String Places = request.getParameter("Places");
  68.  
  69.         MultipartRequest multipartRequest = new MultipartRequest(request, getServletContext().getRealPath("/images/"), /* 1MB */ 1024 * 1024, new DefaultFileRenamePolicy());
  70.         if (multipartRequest.getParameter("save") != null) {
  71.             upload(request, response, multipartRequest);
  72.         } else {
  73.             throw new IOException("Display Upload Dialogue");
  74.         }
  75.  
  76.  
  77.         } catch(Exception e) {
  78.             response.sendRedirect("Error.jsp?error=Entry of new trip failed. Please try again! Error is " + e.toString());
  79.             out.close();
  80.         }
Apr 11 '10 #1
2 8420
MusoFreak200
96 New Member
hello newcomer...

i think that you may get better results if you uploaded this thread into the Java section...

i for one have no idea how to do what you wanna do but i think someone may know inside the other section...

try to rename to your thread asking on the front, how to...

thanks mate...
cya
MusoFreak200
Apr 16 '10 #2
i have servlet code for inserting the image and retrieving the image in database(MS-Access)
Sep 27 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1698
by: Bura Tino | last post by:
Hi, I developing a system using JSP. People familiar with this technology know that ServerPages are easier to maintain than Servlets, but they can only have ASCII output. With that as the backdrop, here's what I want to accomplish. I want clicking on a link to cause a script to be executed on the server but -->I don't want the browser to jump to another page<--.
1
2166
by: joe | last post by:
Any articles relating with Uploading images files to server and resize the image by asp.net 2.0
2
6971
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
2
5957
by: prakharv | last post by:
Hi All, Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it doesn't works on IE. Please, help me out as I am new to this and would be highly thankful if anyone has running code for uploading image files to the server using CGI either Perl or C. This code i took it from net only. #!/usr/bin/perl -w
9
3527
by: Carey Carlan | last post by:
Can the bright minds here point me to the java tools best suited to interfacing a C++ library with the widest range of web servers? Fundamental question from a Java newbie. I'm about to start a web app with the business logic contained in a C++ DLL (could be a COM object if necessary). It must be compiled to protect the intellectual property within. My research to date indicates that java is both portable and powerful enough to manage...
2
1584
by: pdesai007 | last post by:
hi all, i am trying to upload a image on to server with asp and AJAX, but it is not worked. so please give me information that upload an image to the server with java script without refeshing my original page. thank you,
2
1671
madhoriya22
by: madhoriya22 | last post by:
Hi, while deploying applicatin tomcat server is throwing these exceptions :-- SEVERE: Servlet.service() for servlet RequestHandler threw exception java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:415) at java.lang.Integer.parseInt(Integer.java:497) at com.spi.defecttracker.controller.RequestHandler.processRequest(RequestHandler.java:54) at...
1
2078
by: thulaseeram | last post by:
I am using iframe to store uploaded images, it is uploading fine in IE but it is not happening in firefox means first time it is uploading image if i try to upload second image it is not calling even java script function and not uploading the image in firefox. I am using this code in the button onclick event "attach_frame.upload();" here attach_frame is the iframe name and id to which the uploaded image should add. please can any one help me to...
3
2046
by: jatin299 | last post by:
hi ..problem in uploading image..using servlet to upload image in mysql..use html form so user given the path of image..but giving error.here is the code..help me on this. import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class LoadImage extends HttpServlet{
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.