Uploading a photo in a jsp page

hi Friends,
i have 4 fields
Date <takes system date>
Description<description of the photo>
Path< has a text box > Upload <is a button>
I want to upload photos on click event of a button and the the path of where my photo is located , that shud be entered in the path text box
and then I have a button Save
when i click on 'Save ' , it shud save the link in database as well as show the uploaded photo in apge called 'Photos.jsp"
basically my query is how i upload photo thru jsp ?
thnx in advance

Here is the solution to your problem dear.
just set the attribute of form ENCTYPE="multipart/form-data" and call this servlet from your jsp page
//=============================This Servlet stores image
import myConPack.Connect; //my own class to connect to db
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class UploadIntoDB extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
     PrintWriter out=response.getWriter();
     String contentType = request.getContentType();
//IF FORM HAS PICTURE ALSO THEN IF CONDITION WILL EXECUTED FOR WRITING IMAGE INTO DB
     if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
     DataInputStream in = new DataInputStream(request.getInputStream());
     int formDataLength = request.getContentLength();
     byte dataBytes[] = new byte[formDataLength];
     int byteRead = 0;
     int totalBytesRead = 0;
     while (totalBytesRead < formDataLength)
     byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
     totalBytesRead += byteRead;
     String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
          saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
     saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
     int lastIndex = contentType.lastIndexOf("=");
     String boundary = contentType.substring(lastIndex + 1,contentType.length());
     int pos;
          pos = file.indexOf("filename=\"");
          pos = file.indexOf("\n", pos) + 1;
          pos = file.indexOf("\n", pos) + 1;
          pos = file.indexOf("\n", pos) + 1;     
     int boundaryLocation = file.indexOf(boundary, pos) - 4;     
     int startPos = ((file.substring(0, pos)).getBytes()).length;
     int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
     ByteArrayInputStream bais=new ByteArrayInputStream(dataBytes,startPos,(endPos-startPos));
     //========================================
     if((bais.available())>0)
     try{
          Connect connect=new Connect();
          Connection con=connect.getConnection();
          String SqlQuery="insert into tbl values(?,?)";          PreparedStatement pst=con.prepareStatement(SqlQuery);
          pst.setString(1,saveFile);//filename of image
          pst.setBinaryStream(2,bais,bais.available());//image itself
          int result=pst.executeUpdate();
          System.out.println(result+ "Row Added");
     }catch(Exception e) { System.out.println("Exception : "+e); }
     RequestDispatcher rd=request.getRequestDispatcher("/backto.jsp");
     if(rd!=null)
          rd.forward(request,response);
     else
out.println("NO IMAGE WAS Found ");
     }//if closed
}//function closed
}//class closed

Similar Messages

  • Uploading a file in a jsp page

    Hii Javaites
    I am developing an application in which i need to upload file from a jsp page, right now i am using tomcat can anyone tell me the code for uploading a file.
    Thanking in Advance

    Hi,
    For uploading file from jsp:
    1) Goto javazoom.com, then download latest version for upload the files.
    2) Extract the zip & thay giving four jar files
    they are:
    i)uploadbean.jar
    ii)struts.jar
    iii)fileupload.jar
    iv)cos.jar
    put all this jar in lib of u r web application
    ex:
    C:\jakarta-tomcat-5.0.25\webapps\URWEBAPP\WEB-INF\lib\
    3) Set it in class path
    4) create one jsp with file option<input type='file' name = 'somename'>
    5) In action page(next page)
    <%@ page language="java" import="javazoom.upload.*,java.util.*" %>
    <%@ page errorPage="error.jsp" %>
    <jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
    <jsp:setProperty name="upBean" property="folderstore" value="c:/uploads" />
    </jsp:useBean>
    Set the folder where u want upload the particular file.
    MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
    Hashtable files = mrequest.getFiles();
         UploadFile file = (UploadFile) files.get("somename");//Give name u r given in the previous page.
         String fileName = file.getFileName();     
    upBean.store(mrequest, "userFile");
    follow this steps it works fine.
    regards
    DRA

  • How to upload a photo on a Facebook page, NOT in the profile?

    Hi, I have the problem to publish an album on a Facebook page, but I'm only capable to publish the album (or the photo) in the profile. Any suggestion?
    Thanks

    The Facebook publish plugin is very basic - anything else you need to do has to be done the conventional way via their website (and quite frankly it's better to use the website anyway, so you can fix the descriptions and tags).

  • Help with uploading a photo

    I am trying to upload a photo to a web page it must be 1920X1920 pixels baseline standard JPEG fle size less than 1.8 mbsaved as RGB.
    This is what I have done so far.  Set the color profile first then set the  size to 1920x1920 pixels then saved the file both to web and this  makes the size too large when I save this file it saves as 3.0 mb.  Can I change the size? the website requires the size to be less than 1.8 mb

    Open your jpeg image in full edit.
    Select the crop tool.
    On the options bar select custom and enter your dimensions and choose 300 ppi.
    Drag out the crop tool across your image and drag inside to move it to your best position.
    Hit the check mark and choose Save As + sRGB
    Your image will be the exact measurements and well within the maximum file size.
    Click image to enlarge.

  • How to upload an image in jsp page

    hi,
    I want to upload an image file with my jsp page, but i cannot do it,
    I have used Jakarta common file upload for this & i have also read following file. But my code isnot working properly? Can you give me any example how to upload an image & how to display it?
    Can u give me any source code? Please help me.
    http://jakarta.apache.org/commons/fileupload/using.htmlwith regards
    Bina

    Hi,
    But after writing the following code i have got following error? What's the problem of this code? please help me?
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    <%@ page import="org.apache.commons.fileupload.*" %>
    <%@ page import ="java.util.*" %>
    <%@ page import ="java.io.*" %>
    </head>
    <body>
    <%
    boolean isMultipart = FileUpload.isMultipartContent(request);
    DiskFileUpload upload = new DiskFileUpload();
    List items = upload.parseRequest(request);
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    if (item.isFormField()) {
    String name = item.getFieldName();
    String value = item.getString();
    //ring name= request.getParameter("")
    %>
    <%= name %>:<%= value %>
    <%
    } else {
    %>
    <%
    InputStream stream = item.getInputStream();
    OutputStream bos =
         new FileOutputStream(getServletContext().getRealPath("/images"+"/"+ item.getName()));
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
    bos.write(buffer, 0, bytesRead);
    bos.close();
    stream.close();
    item.delete();
    %>
    </body>
    </html>Error is:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    FileUpload cannot be resolved
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    DiskFileUpload cannot be resolved to a type
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    DiskFileUpload cannot be resolved to a type
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    FileItem cannot be resolved to a type
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    FileItem cannot be resolved to a type
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    FileUpload cannot be resolved
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    DiskFileUpload cannot be resolved to a type
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    DiskFileUpload cannot be resolved to a type
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    FileItem cannot be resolved to a type
    An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
    Generated servlet error:
    FileItem cannot be resolved to a type
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Please help me.
    With regards
    Bina

  • How to display uploaded image in jsp page.

    Hello,
    I am using struts 1.2.9 and and have uploaded image on the server. Now what I want to do display the image in jsp page after clicking on one link in jsp. I have tried many thing to display image in jsp page. But I am getting an error during displaying image in jsp. I have displayed absolute path in servlet. and used InputStream and outputstream to display image in jsp page.
    Can any one help.
    Thanks in advance
    Manveer Singh

    Follow this. This topic is very popular recently on the forum.

  • How do I upload a photo to my profile on a web page?

    I am using Lion OX and iPhoto 11.   I have a profile page on one of my programs and need to upload a photo.  I have been so far unsuccessful.    I follow the directions on the particular page I am trying to upload to:   i.e.   'Choose Photo' and then 'Upload'      All I get is a neverending spinning ball.  Is there something I am missing in my procedure.     I know the photo I want, I choose it within the iphoto program, then click upload on the profile page I am trying to get the photo uploaded to.    Am I missing something?     I can upload to Facebook without problem, but not this particular program.   I did have a picture on it when using iPhoto 9, and decided yesterday to change it -- now there is nothing in the photo space at all.

    I am trying to upload a profile photo to www.Logos.com.  I did it before with iPhoto 9, but now that I have iPhoto 11, there doesn't seem to be any place on the Share menu item to allow me to just upload -- I have to depend on Logos to do the work.   
    I can access the iPhoto Library from my Home settings.   This brings up all the photos, from which I choose one by highlighting it, and respond on the profile page website "Upload"     All I get is a spinning ball and there is no action on my modem that anything is happening.    I've never tried to access the iPhoto Library from iMovie.    I have had no need to, at least I don't think I have a need.

  • TS3899 I can  no longer send photos in an email from my iphone 5. It uploads the photo to the "new message" page - and then it freezes. I can use safari and check my emails, and when the email part is frozen the rest of the phone works fine ! any advice?!

    I can no longer send photos in an email from my iphone 5. It uploads the photo the the "mew message" page and then it freezes! I can use safari and check my emails, and when the email part is frozen I can still use the rest of my phone. Any advice ?!?

    Hi, ireland a. 
    I would recommend closing any open applications in multitasking and restarting the device.  If unfamiliar with multitasking, I have included a screenshot on how to process an application close. 
    iOS: Force an app to close
    Once these steps are processed, attempt to send the photo again. 
    iPhoto for iOS (iPhone): Send photos by email
    http://support.apple.com/kb/PH3271
    Regards,
    Jason H. 

  • Display uploaded file on JSP page

    Hi All,
    I want to display uploaded file in JSP.
    Initially I am displaying File Name after saving the file & click on edit link.
    i.e on JSP Page I have File Upload component & save button.With that save button I am saving my file to databse.
    So when I click on edit link I am getting that file name from Databse then I am displaying it.
    But now I want to display uploaded file name on JSP page before saving to databse.i.e I will have browse & Upload button.When I click on browse button I will open window from where I will select file.
    This is working fine as,<x:inputFileUpload id="uploadfile" value="#{errorLotBean.file}" storage="file"></x:inputFileUpload>
    But when I click on upload button that uploaded file should be displyed there only.Can anyone please tell me how to do this ?
    Thanks
    Sandip

    Thanks a lot Siefert,
    I tried the way mentioned in URL.
    But what if I want to display all uploaded file on my screen.
    i.e. If user click on browse & select File A then click on upload button.
    (Here the File A will be displayed) with code
    <h:outputtext value="#{benaName.file.name}"
    But what if after displaying File A if user decide to upload another file File B.
    How to display that ?
    with <h:outputtext value="#{benaName.file.name}" its dispalying one file only.
    Thanks
    Sandip

  • Error with Portal JSP Page Upload

    i've run into a problem with trying to deploy custom JSP pages to Portal. basically, if i enable JSP page types for the Page Group, generate a simple page, download it using the Download JSP link, and then try to upload it again as a JAR or WAR via the JSP Source tab, even without modifying the page at all, i receive the following error:
    Unexpected error - User-Defined Exception (WWC-35000)
    Unexpected error - User-Defined Exception (WWC-35000)
    Path ID does not exist. (WWC-50001)
    i've tried logging in as ORCLADMIN in case it was a permissions thing, but that didn't help.
    anyone else experience this? any ideas?
    thanks,
    .rich

    i've run into a problem with trying to deploy custom JSP pages to Portal. basically, if i enable JSP page types for the Page Group, generate a simple page, download it using the Download JSP link, and then try to upload it again as a JAR or WAR via the JSP Source tab, even without modifying the page at all, i receive the following error:
    Unexpected error - User-Defined Exception (WWC-35000)
    Unexpected error - User-Defined Exception (WWC-35000)
    Path ID does not exist. (WWC-50001)
    i've tried logging in as ORCLADMIN in case it was a permissions thing, but that didn't help.
    anyone else experience this? any ideas?
    thanks,
    .rich

  • How can I upload a photo to someone's facebook page?

    I can upload a photo from iphoto to my facebook page, but how do I upload photos to a friend's facebook page?

    Sme as uploading any photo to any website. The first of these is what you want:
    There are many, many ways to access your files in iPhoto:   You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Command-Click for selecting multiple pics.
    (Note the above illustration is not a Finder Window. It's the dialogue you get when you go File -> Open)
    You can access the Library from the New Message Window in Mail:
    There's a similar option in Outlook and many, many other apps.  If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto.
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    If you want to access the files with iPhoto not running:
    For users of 10.6 and later:  You can download a free Services component from MacOSXAutomation  which will give you access to the iPhoto Library from your Services Menu.
    Using the Services Preference Pane you can even create a keyboard shortcut for it.
    For Users of 10.4 and 10.5 Create a Media Browser using Automator (takes about 10 seconds) or use this free utility Karelia iMedia Browser
    Other options include:
    Drag and Drop: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    File -> Export: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, producing a copy.
    Show File:  a. On iPhoto 09 and earlier:  Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.    3.b.
    b: On iPhoto 11 and later: Select one of the affected photos in the iPhoto Window and go File -> Reveal in Finder -> Original. A Finder window will pop open with the file already selected.

  • How to upload photos to a facebook pages?

    Bonjour tout le monde. Je souhaite transférer vos photos directement sur ma page facebook. Malheureusement, il semble impossible. Avez-vous une solution?

    janolebateau wrote:
    hello everyone. I wish to upload your photos directly on my facebook page. Unfortunately it seems impossible. Do you have a solution?
    Hi janolebateau,
    There are 2 plugins which support facebook uploading:
    * Adobe's
    * Jeffrey Friedl's
    If I were you, I'd use Jeffrey Friedl's, but many prefer to use Adobe's if it suits their needs well enough.
    http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB8QFjA A&url=http%3A%2F%2Fregex.info%…
    Rob

  • I made a Photo Book in Lightroom 5.5 converted to jpg and tried to upload to Shutterfly. The only page that I had text added in will not show up in the online Book!!  Thanks For Your Help,  Scott

    I Made a Photo Book in Lightroom 5.5 converted to jpg and tried to upload to Shutterfly. The only page that had text added in will not show up in the online Book!!!  Help,  Scott

    There's a whole lot to read in your post, and frankly I have not read it all.
    Having said that, this troubleshooting guide should help:
    http://support.apple.com/kb/TS1538
    In particular, pay attention to the mobile device support sections near the bottom, assuming you have already done the items above it.

  • My I pad 1 sometimes while watching working switches off and go back to home page ... Why ? Also I need to know how I can upload my photos and pictures from laptop to my I pad.  I tried thru I tunes but not work.

    My I pad 1 sometimes while watching working switches off and go back to home page ... Why ? Also I need to know how I can upload my photos and pictures from laptop to my I pad.  I tried thru I tunes but not work.

    Satmar wrote:
    My I pad 1 sometimes while watching working switches off and go back to home page ...
    Try This...
    Close All Open Apps... Sign Out of your Account... Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    Wait for the Apple logo to Appear...
    Usually takes about 15 - 20 Seconds... ( But can take Longer...)
    Release the Buttons...
    Note:
    Also consider Deleting any Apps you have Purchased / Downloaded but you now never use...
    Satmar wrote:
    Also I need to know how I can upload my photos and pictures from laptop to my I pad.
    See Syncing photos to devices
    Here  >  http://support.apple.com/kb/HT4236

  • File upload in oracle9i using JSP page from browser

    Hi guys
    I need to store a pdf file from the JSP page into the Oracle9i DB.
    FrontEnd: Netbeans6.0
    Backend: Oracle9i db server
    I need Jsp code and table creation code i want to create in the Database.
    Pls help me out it is urgent.

    Javamu wrote:
    Hi guys
    I need to store a pdf file from the JSP page into the Oracle9i DB.
    You mean Servlet.
    FrontEnd: Netbeans6.0Netbeans is not a front end to anything. It is an IDE.
    Backend: Oracle9i db server
    I need Jsp code and table creation code i want to create in the Database.This site is not a place to get codes. This site is a place to get help with codes you have written. This site is also not an Oracle or general database or SQL question support forum.
    Pls help me out it is urgent.If it is urgent then you are cooked.
    You can start learning about the various things you need here
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
    http://java.sun.com/docs/books/tutorial/jdbc/index.html

Maybe you are looking for

  • How can anyone see message on a locked iPad mini if it was not connected to wifi?

    Hi, My new iPad mini wifi was stolen 2 months ago in Spain. It was locked with 4 digit code. I immediatelly locked it through Find my iPhone, commanded erase and added info to call me with my mobile number. In FMIP it says it's not connected and it's

  • Got my new Mac Pro: keyboard / iLife

    Today I received my Mac Pro through TNT. I live in Switzerland. Upon opening the box, I realized the box contains the older, white keyboard (instead of the brushed metal version). I assume iLife 06 may be there, in place of iLife 08. Question: can I

  • Oracle.adf.view.rich.context.ExceptionHandler is not working properly

    Hi, I am using Jdev 11.1.2.0.0 and weblogic server (10.3.5). I have overridden oracle.adf.view.rich.context.ExceptionHandler class and registered under ADF Meta-INF/services folder. when I am deploying in the local machine it is working fine, but in

  • Missing Purchase.

    I have recently purchased 1000BC from Playstation Store for Planetside 2 and I am yet to recieve it. I have the receipt in the email, on my account transaction history. I talked to customer support of Planetside 2 who I initially inquired at regardin

  • Incremental Backup Script ?

    I'm plannig to implement INcremental level backup policy with Incrmental backup every day and full backup every week on Sunday. plz can anybody help with the basic script of this backup policy. do we will have 2 different script each for Incremental