I have made two Text box in a JSP page which will prompt user to enter his name and upload his photograph. My question is: 1) How an image is uploaded (I mean what will the code for it). 2) I 'trap' user name in a temporary variable by using request.getParameter(name) How to trap the .gif/.bmp image file? 3) How to save it in database so that it can be displayed later on? Thanks in advance.
Rajesh(Bangalore,India)<br />SCJP2, SCWCD, SCEA, IBM-XML, UML-OOAD, IBM-Enterprise Connectivity with J2EE.
I would highly recommend reading the following articleUpload file bean The main points are: Client-Side ----------- * form must be of enctype multipart/form-data * use the <INPUT type="file"> element for file upload Server-Side ----------- * Servlets cannot handle multipart/form-data, so need to write own code to handle the stream (the article gives sample code) * Once you have extracted the file from the servlet input stream, you can write to database You may also like to check out the following article Filter code for Servlet 2.3 which describes how you can use a file upload filter which overrides the getParameter() methods to be able to get file parameters. The articles are quite explanatory, and you can either write your code adapted from the articles, or use the com.oreilly.servlet.* package which already implements most of this functionality.
Hi Try this URL. It provides you with an easy interface (MultipartRequest) for handling file uploads. http://www.servlets.com/cos/index.html. Also in the client side you should use the <input type = file ...> element to enable file uploading instead of normal <input type = text ...>.
Joined: May 27, 2002
I forgot to mention explicitly that the support of filters is new functionality that has been included in servlet spec 2.3; older servlet specs don't have this functionality. (Tomcat 4.0 uses servlet spec 2.3; Tomcat 3.2 uses servlet spec 2.2)
First of all the form should have the following: enctype="multipart/form-data" this is very different from a simple form. In these cases you use predefined classes to get the parameters from the form: The two classes I know are: oreilly classes JSPSmartUpload I've used jspsmartupload to upload images in a servlet. Have a look at these classes and good luck.
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury