Hello, i tried to upload a picture and pass it from (upload_pic.jsp) to (show_pic.jsp)pages in order to store it in a Mysql table as a BLOB type, but i run into an Exception of 1 error in(show_pic.jsp)page as the following :
incompatible types found : java.lang.String required: java.sql.Blob Blob img=request.getParameter("pic_");
this is part of (upload_pic.jsp) <form method="post" action='<%= response.encodeURL("show_pic.jsp") %>'> <input type="file" name="pic_" /><br> <input type=submit value=upload ></form>
and this is part of (show_pic.jsp) <body> <% Class.forName("org.gjt.mm.mysql.Driver"); Connection cnct = DriverManager.getConnection("jdbc:mysql:///propertysearch"); Statement stmt=cnct.createStatement(); Blob img=request.getParameter("pic_");
get and set attribute have nothing to do with this issue.
First, in order to upload a file, you need to specify that the form is submitting a multi-part request. The default enctype of the form tag will not do.
Secondly, once you do that, the HttpServletRequest will no longer automatically parse your request. You'll either have to do it yourself, or use one of the 3rd party libraries floating around to do it for you.
Search this, the JSP and perhaps the Tomcat forum for more information on file uploading.
As pointed out you should use the enctype of your form to be enctype="MULTIPART/FORM-DATA" so that the content of your file gets embeded into your request object. But then now you cannot use the request objects method to retrieve the values of any parameter of the submitted form. you have to use third party packages. You can get all that you want to achieve this on the following link.
web page [ June 04, 2004: Message edited by: Johnson Abraham ]