How can i get a file object on servlet

i want to send a file object to be sent on a servlet from html input file tag. This is the HTML code
<form action="uploadImage.jsp" method="post"><br><br>
            <table width="400px" align="center" border=0 style="background-color:ffeeff;">
                <tr>
                    <td align="center" colspan=2 >
                        Image Details</td>
                </tr>
                <tr>
                    <td align="center" colspan=2> </td>
                </tr>
                <tr>
                    <td>Image Link: </td>
                    <td>
                        <input type="file" name="filename" id="file">                     
                    <td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="Submit" value="Submit"></td>
                </tr>
                <tr>
                    <td colspan="2"> </td>
                </tr>
            </table>
        </form>On servlet i have tried this code.
                                String file = request.getParameter("filename");
                                    if (file != null) {
                                        out.println(file);
                                        File f = new File(file);
                                        out.println(f.isFile());
                                        out.println(f.length());
                                    }this code is showing following output.
       DSC01347.JPG false 0 so is there any way of transferring the the file on servlet without using common file upload?
Please help me

i have worked out this following solution. It is working here.
* To change this template, choose Tools | Templates
* and open the template in the editor.
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
* @author Chinmay
public class NewServlet extends HttpServlet {
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        Part p = request.getPart("file");
        out.println(p.getContentType());
        out.println(p.getName());
        out.println(p.getSize());
        InputStream in = (InputStream) p.getInputStream();
        byte[] b = new byte[in.available()];
        in.read(b,0,b.length);
        Connection connection = null;
        PreparedStatement stmt = null;
        try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Properties properties = new Properties();
        connection = DriverManager.getConnection("jdbc:odbc:sn", properties);
        stmt = connection.prepareStatement("insert into Photos(username,photo) values(?,?)");       
        stmt.setString(1, "a");
        stmt.setBytes(2, b);
        int rows = stmt.executeUpdate();
        if (rows > 0) {
        out.println("INSERTED");
        } catch (ClassNotFoundException ex) {
        out.println(ex);
        } catch (SQLException ex) {
        out.println(ex);
        } finally {
        in.close();
        try {
        connection.close();
        stmt.close();
        } catch (SQLException ex) {
        ex.printStackTrace();
        out.close();
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
     * Returns a short description of the servlet.
     * @return a String containing servlet description
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}this code is storing the image in database.
But not the main problem is this code is working on my PC. But when i executed this code at my institute's PC it shows me error that cannot find symbol for this line.
import javax.servlet.http.Part;In my institute we have Netbeans 5.5.1 and tomcat server or sun app server.
On my PC I have Netbeans 6.9.1 and Glassfish server.
So what can be the problem?
Is it a problem of server or just servlet's jar file???

Similar Messages

  • How can I get a file to copy all of the files in a directory except itself and the source of the copy function will be the directory the final program is in?

    How can I get a file to copy all of the files in a directory except itself and the source of the copy function will be the directory the final program is in? This application must be in Lab View 8.

    you mean something like this (see below)?
    Now you may have to implement code to check if the destination folder exists and to create it, etc.  But if you use the Front Panel Control to select the destination folder, it should be okay.
    Not the best implementation, mind you but you'll get the idea..
    Message Edited by JoeLabView on 04-18-2007 03:43 PM
    Attachments:
    copy folder contents.PNG ‏10 KB

  • How can I get my files in my ipad 3(using keynotes) to my PC?

    I store my document in my keynote and I want to get it through my PC. How can I get those files?

    Download and Install the Windows Support Software (1st task in Boot Camp).

  • How can i get a file header using this method cl_gui_frontend_services= gui

    Hi Experts,
    How can i get a file header using this method cl_gui_frontend_services=>gui_download
    Thanks
    Basu

    Hi,
    You can use the FM - GUI_DOWNLOAD to specify the headers. It can be done in the following manner -
    TYPES: BEGIN OF ty_head, "Structure for header
                 h(10) TYPE c,
                 END OF ty_head.
    DATA: it_head  TYPE TABLE OF ty_head WITH HEADER LINE.
    "Adding header details
    it_head-h = 'Field1'.
    APPEND it_head.
    it_head-h = 'Field2'.
    APPEND it_head.
    it_head-h = 'Field3'.
    APPEND it_head.
    it_head-h = 'Field4'.
    APPEND it_head.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                        = p_file
       filetype                        = 'ASC'
       write_field_separator           = 'X'
       header                          = '00'  "<= note this
      TABLES
        data_tab                        = it_tab
       fieldnames                      = it_head[] "<= Pass your header table here
    EXCEPTIONS
       OTHERS                          = 1.
    Hope this helps.
    Regards,
    Himanshu

  • I bought a mac air retina to replace a mac pro. How can I get all files of the back up and copy them to the new mac?

    I bought a mac air retina to replace a mac pro. How can I get all files of the back up and copy them to the new mac?

    Mail window may be in the Full Screen mode.
    Move the mouse pointer to the top right corner of the Mail window and hold it there.
    Menu bar should drop down and click the blue double arrow icon.
    Full Screen toggle shortcut:  control + command + F

  • How can I get the File, Edit, View, Windows ect to show in Organiser

    While on various tutorials they all show a
    menu of file, edid, view ect in the top left hand corner of the screen, mine shows only a small square box that when clicked give you the option of restore, close minimise ect. How can I get the file edit menu to show. Should have said in Photoshop Elements 9.

    Thanks Barbara that's done the trick

  • How can i get the file on my old PC Laptop to my iMac, how can i get the file on my old PC Laptop to my iMac

    how can I get the files on my old PC Laptop to my Imac

    If you want all of them, see OS X Lion: About Windows Migration Assistant

  • How can you get video files to play properly from a Fujifilm X20

    How can I get movie files  from my Fujifilm X20 to play properly in imovie?

    OS (windows Xp) will not let me.
    Why will it not?  What is the error message?  How are you trying to transfer them?
    There are lots of ways of moving files.
    A simple and popular way to copy files and share files amoung your devices. This will depend on you internet connection speed.
    https://www.dropbox.com/
    Using iTures to transfer files:
    http://support.apple.com/kb/HT4094?viewlocale=en_US&locale=en_US
    Files Connect -- The swiss army knife of remote file connect
    https://itunes.apple.com/us/app/files-connect/id404324302?mt=8
    Windows File server
    http://itunes.apple.com/us/app/filebrowser-access-files-on/id364738545?mt=8
    "In education and business users increasingly expect to be able to access their data anytime, anywhere and from any device."
    http://www.minnow.it/
    This thread has good info.
    https://discussions.apple.com/thread/3708341?tstart=0
    How to transfer files from your iPad to your PC with iPad to Computer Transfer
    http://www.iphone-mac.com/how-to-transfer-and-sync-contents-from-ipad-to-pc.html
    Try the combo of:
    Diskaid on your computer and FileAppPro on your iPad
    Good old FTP
    FileApp and FileApp Pro

  • How can I store a File object into a Vector and get it back

    hi there
    I need to store a number of File object into a Vector first, and later on I need to get each File object out and work with it.
    Vector mylist;
    File[] myfile;
    ....get a list of files from using File Chooser
    mylist = new Vetor();
    for (i=0;i<myfile.length;i++){
    mylist.add(myfile);
    ..how do I get them back? i try to do this way
    for (i=0;i<mylist.size(); i++)
    File tempfile = mylist.get(i);
    ..work with tempfile. but I got java.lang.object error: imcompatible types. what can I do?

    Vector mylist;
    File[] myfile;
    ....get a list of files from using File Chooser
    mylist = new Vetor();
    for (i=0;i<myfile.length;i++){
    mylist.add(myfile);
    ok try this: i don't reall understand what your trying to do though...
    File[] files;
    // get files
    Vector fileList = new Vector();
    for (int i = 0; i < files.length; i++)
      fileList.add(files);
    // to get them out.
    for (int i = 0; i < fileList.size(); i++)
    ((File)fileList.elementAt(i)).toString();
    // or
    // to get them out.
    for (int i = 0; i < fileList.size(); i++)
    File temp = (File)fileList.elementAt(i);
    System.out.println(temp.toString);

  • How can I get the underlying object from the ObjectReference

    Dear friends,
    I think this question has been asked a couple of times. But, I am still wondering if anybody has found an answer to it. Maybe this is some common need ...
    I would like to get the underlying object for which the ObjectReference is
    a mirror For example, I have a class Customer in my application, and I can get an ObjectReference through JDI during runtime. But how can I get the target VM's object which is a real instance of Customer, by which I can invoke methods defined in Customer?
    Thank you so much for any input!
    SunnyDay

    I'll preface this response by admitting this far from an elegant solution, but I did write a function addressing this question, mostly as an exercise.
    If passed an object with an InTextFrame property (Pgf, AFrame, Cell, Fn) that resides in an open document, the function will return the Doc object. Otherwise, it returns undefined.
    function getParentDoc(testObj) {
        //Get object for current page
        try { var curPage = testObj.InTextFrame.FrameParent.PageFramePage; }
        catch(er) {return;}
        //Step backwards to first page in document
        var prevPage = curPage.PagePrev;
        while (prevPage.ObjectValid())
            curPage = prevPage;
            prevPage = prevPage.PagePrev;
        //Compare with first pages of open documents
        var testDoc = app.FirstOpenDoc;
        while (testDoc.ObjectValid())
            if (curPage.id==testDoc.FirstBodyPageInDoc.id) return testDoc;
            testDoc = testDoc.NextOpenDocInSession;    
        return;
    To your PPS: Rather than seeing the native framework grow bloated to address additional features, I would love to see Adobe and other developers publish libraries of useful functions and class extensions.

  • How can you get your files from outlook onto your ipad2 and keep it in the files?, how can you get your files from outlook onto your ipad2 and keep it in the files?

    How can you get files from your outlook folder from the ipad2 and keep it there for future reference?

    It's unclear what you are asking outlook is a mail, appointment, tasks and contacts
    Programs outlook have no direct contact with files

  • How can I get specific files back from my Time Machine backup?

    I wanted to make a fresh install on my MacBook Pro, in order to only have Java 8 instead of any older Java versions. So far so good. But now I want to get specific files/libraries from my external backup (USB):
    One Parallels Virtual Machine
    My old mail
    My iPhoto Library
    I don't need any settings for these, since I can easily configure them again.
    I already used the Migration Assistent to restore all apps.
    How can I get specific data back from the backup without restoring all stuff that I don't want anymore?
    I'm now working on a new account on the fresh system, called 'Admin'. My old account was called 'Hans' (or 'hans') and I'd like to create such an account again for all my tasks.
    Hans

    How can I get specific data back from the backup without restoring all stuff that I don't want anymore?
    I'm now working on a new account on the fresh system, called 'Admin'. My old account was called 'Hans' (or 'hans') and I'd like to create such an account again for all my tasks.
    You will want to add the same User account(s) which hold the data you want to restore. So you will want to add a User account of 'Hans or hans'. Check your Time Machine back up drive to see how the User account is labeled (Hans or hans). Navigate to the Users folder and see how it's labeled.
    You can then use your Time Machine back up drive and navigate to the User Home folder to copy its data over (e.g. contents from Documents, Downloads, Music, Pictures, etc.). Repeat for other Users.

  • How can I get settings files out of the Library folder?

    I had to do a clean reinstall (erase & reinstall) to clear up some problems on my Mac. Unfortunately, when you do this, your settings, customizations, bookmarks etc. aren't transferred over as they do when you upgrade in the normal way.
    For example, dashboard widgets are in each user's <home folder>/Library/Widgets folder.
    I could restore some of these settings by dragging the settings files from the old System Folder to the new one. Unfortunately, Apple is making this harder by hiding the Library folder in the user folder, both on the Mac and on the backup drive.
    There is a command to enter in Terminal to show your Library folder, but this only seemed to work on the Mac and not on my backup drive.
    How can I get key settings files out of the Library folder on my backup drive when the Library folder is hidden?
    Thanks

    Open the enclosing folder, choose Go to Folder from the Finder's Go menu, and provide Library as the path.
    (80699)

  • HOW CAN I GET ORIGINAL FILE OF A PHOTO FROM IPHOTO

    CAN I GET ORIGINAL FILE OF A PHOTO FROM IPHOTO

    File -> Export
    Set the Kind to Original.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.
    Regards
    TD
    p.s. Please don't type in block capitals. They're harder to read, and on the forum it looks like you're shouting at everybody.

  • How can I get the file to unlock my mac mini after hacking my Apple ID?

    Once hacked my account, the hacker deleted all my mobile devices and blocked MacBook and MacMini. Mobile devices I unlocked by the phone with customer support Apple. MacMini unlock failed. How do I get a file to unlock if i have a hash tag?

    In my country, offer to drive to a service center. I want to do it myself.

Maybe you are looking for