How to store and retriew .pdf or .doc using file uploader component

hi,
I want to store a .pdf / .doc file in the database and retiew it. I am using
sun studio enterprise for EJB developing(sun application server as the container) , Oracel as DBMS and sun studio creator for frontend.
kaushalya

public String saveButton_action ()
        // TODO: Process the button click action. Return value is a navigation
        // case name where null will return to the same page.
        tagsDataProvider1.cursorLast ();
        //UploadedFile f = fileUpload1.getUploadedFile ();
        if (fileUpload1.getUploadedFile ()!=null)
            tagsDataProvider1.setValue ("attachment",fileUpload1.getUploadedFile().getBytes ());
            tagsDataProvider1.setValue ("attachmentfilename",fileUpload1.getUploadedFile().getOriginalName ());
            tagsDataProvider1.setValue ("attachmentcontenttype",fileUpload1.getUploadedFile().getContentType ());
        tagsDataProvider1.commitChanges ();
        return "home";
    }This servlet returns the data to the user unadulterated:
* FileView.java
* Created on October 6, 2005, 4:50 PM
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
package docman;
* @author USER
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
public class FileView  extends HttpServlet {
String ct;
String type;
    /** Creates a new instance of DisplayPicture */
    public FileView() {
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    public void destroy() {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String id=request.getParameter("id");
        type=request.getParameter("type");
        //String ct=request.getParameter("contenttype");
        //if ((ct==null)||(ct.equals(""))) {
            //ct="image/x-jpeg";
            //ct="image/bmp";
        System.out.println("FileView 1.0");
        System.out.println("requested file with ID: "+id+" content: "+ct+" Doctype:"+type);
        try {
            ServletOutputStream out = response.getOutputStream();
            byte[] f=this.getImage(id);
            response.setContentType(ct);
            out.write(f);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
    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
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
        return "Displays a picture from the database identified by a parameter IMAGEID";
    private byte[] getImage(String id) throws IOException {
        Statement sta=null;
        Connection con=null;
        ResultSet rs=null;
        byte[] result=null;
        try {
            Context initContext = new InitialContext();
            Context envCtx = (Context) initContext.lookup("java:comp/env");
            DataSource ds = null;
            try{
                 ds = (DataSource)envCtx.lookup("jdbc/xxxxx");
            }catch ( javax.naming.NameNotFoundException ex){
                log("No context found for jdbc/xxxxx in java:comp/env Attempting to look it up in initial context");
                ds = (DataSource)initContext.lookup("jdbc/xxxxx");
            Connection conn = ds.getConnection();
            sta = conn.createStatement();
            if(type==null){rs=sta.executeQuery("SELECT * FROM tags where tagid="+id);}
            else if (type.toLowerCase ().equals("tag")){rs=sta.executeQuery("SELECT * FROM tags where tagid="+id);}
            else if (type.toLowerCase ().equals("crewdoc")){rs=sta.executeQuery("SELECT * FROM crewdocumentation where docid="+id);}
            if (rs.next()) {
                result=rs.getBytes("attachment");
                ct=rs.getString ("attachmentcontenttype");
                System.out.println("bytes returned : "+result.length);
            } else {
                System.out.println("Could find image with the ID specified or there is a problem with the database connection");
            rs.close();
            sta.close();
            conn.close();
        } catch (Exception e) {
            log(e.getMessage());
            e.printStackTrace();
       // ByteArrayOutputStream output = new ByteArrayOutputStream();
        //output.write(result, 78, result.length-78);
        //output.flush();
        //output.close();
        //return output.toByteArray();
        return result;
}I pinched both from examples i found on this forum using the search facility...
And this hyperlink retreives the file:
<ui:hyperlink binding="#{TagView.tagHyperlink}" id="tagHyperlink"
                                    text="#{TagView.tagsDataProvider.value['tags.attachmentfilename']}" url="/servlet/FileView/?id=%23%7BTagView.tagsDataProvider.value%5B'tags.tagid'%5D%7D+"&"+#{TagView.tagsDataProvider.value['tags.attachmentfilename']}"/>

Similar Messages

  • How to use file upload component inside a portlet

    Hi
    Thank you for reading my post.
    does file upload works inside portlets ?
    can some one help me with a sample code , does it need some tricks ?
    Thank you

    any help is welcomeLegolas,
    You could try your own implementation. Someone was able to implement a file upload with Creator 2004Q4 and the O'Reilly Servlet. See http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=50186.
    You will have to configure O'Reilly Servlet's "MultiPart Filter" in your application. Creator 2 uses a same approach (a filter) to accomplish this. Given that the file upload component is not supported on portlets, this leads me to the following: I don't know anything about portlets and portlet containers, but I'd check first for some architechtural restriction in the portlet subsystem that avoids the use of a filter for a file upload. If think this could be the only thing that will restrict you to implement your own file upload.
    Hope this helps.
    Antonio

  • How to store the rejected messages in bpel using file adapter

    Hi all,
    I am using the file adpter to read the text file.In file some bad messages are there.
    now i can read the correct data.but i can't view rejected messages.
    if im not using "rejectedmessagehandler" , but it is stored in default directory.
    In my application,correct messages are reading but bad messages are not stored in default directory.
    pls can you help on that rejected messages store

    Hi
    You have to define rejectedMessageHandlers in activation agent part of ur fileadpater in bpel.xml.
    ex:
    *<activationAgent*
    className="oracle.tip.adapter.fw.agent.jca.JCAActivationAgent"
    partnerLink="UrPartnerLinkName">
    *<property name="rejectedMessageHandlers">*
    file://YourFolderStructure (Where you want to save your rejected messages... Only folder structure)
    *</property>*
    *</activationAgent>*
    If u have any rejected messages those will be written to a file named as INVALID_MSG_ + process-name + operation-name + current-time in the above structure
    Regards
    PavanKumar.M

  • How to upload multiple files in Webdynpro using File upload Screen Element

    Hi Experts,
          Can anybody tell me how to upload multiple files/pdfs in webdynpro using file upload screen element, and also please tell me what is the maximum storage limit of RAWSTRING data type,Advance Thanks.
    Regards,
    Sandesh

    Hi Sandesh,
    this is simply not supported, not in WebDynpro nor in standard HTML.
    A workaround is to upload a ZIP with all files and on server side unpack the ZIP and operate on the single files.
    I hope it will  help u..
    ----------------------OR-------------------------
    As you know using File upload UI element we can upload only one file at a time. There may be a scenario where user may want to upload any no of files at a time which is not determined at design time. This can be acheived using the ACF UpDownload UI element which requires a security whiltelist to be created
    http://scn.sap.com/docs/DOC-2270
    ----------------------OR-------------------------
    You can use Table UI element.
    Regards,
    Deepak Singh

  • How can I store and share PDF files via iCloud?

    I am trying to use iCloud to store and share PDF files from my PC, iPad2 and iPhone 4S... They are supposedly supported. I can share .docs, .xls, etc.... However, I cannot figure out how to share a pdf!

    Welcome to the Apple Community.
    You can download an iWork document from iCloud as a PDF, but you can't share a PDF document with iWork apps on iOS devices.

  • Any ideas how I can insert a pdf into word, using the insert object option. However the pdf i want to insert has text and lines annotated, but once inserted the comments don't appear????  any help would be greatly appreciated.

    Any ideas how I can insert a pdf into word, using the insert object option. However the pdf i want to insert has text and lines annotated, but once inserted the comments don't appear????  any help would be greatly appreciated.

    You will need to find a forum for MS Word since that is the software that you are trying to manipulate in this.  If you think the processing/creation of the PDF plays a role then you should ask in the forum for the software that you are using to create the PDF.
    This forum is for issue regarding downloading and installing Adobe trial products, so in any circumstance, your issue does not fit in this forum.

  • How to view and print pdf files

    how to view and print pdf files

    Download and install Adobe Reader: Adobe Reader Install for all versions
    Open the PDF file using it. If security restrictions don't prevent it you could also print it.

  • How to store and retrieve blob data type in/from oracle database using JSP

    how to store and retrieve blob data type in/from oracle database using JSP and not using servlet
    thanks

    JSP? Why?
    start here: [http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html]

  • Hello! I just want to know how to open a document (.pdf or .doc).

    I have looked at Labview\vi.lib\platform\browser.llb\Open a Document on Disk.vi but the vi has many subvi's. It works well but when I  build a new application I always get errors when I try to open the document. Thank you.

    Altenbach....  we're gonna start calling you "Hawkeye" 
    There was not much info on the other post other than tst's reply..  I'll check it out..
    Thanks buddy!
    RayR
    EDIT PORTION:
    Humm...  the titles were similar....  "Hello! I just want to know how to open a document (.pdf or .doc) after the press of a control button. Thank you."
    But you're right.. nothing mentioned about a build..  >> SORRY: Not Duplicate Post <<
    Message Edited by JoeLabView on 09-21-2007 11:38 AM

  • LRv3.2 Networking with an Asst , How to store and retrieve updated work on Win7?

    LRv3.2 Networking with an Asst , How to store and retrieve updated work on Win7 Network?
    We have a working 1gig network in Win7 PRO 64-bit.  and using LRv3.2
    * How do I configure our Files or Cataloges "so"  ALL Edits are veiwable/edit to all?   (we don't work on the Same Shoot/Folder at the same time)
    I NEED to see,  ALL the LR  Edits  (is great with DNG files
    *** BUT,  what I cannot see if I remember correctly (with just the DNG sharing)  is the  CROP or Virtual Copys ... possibly the Brush edits.
    HOW, do I configure to be able to read and edit ...  ALL of the updated/saved  Edits???   (after it is done by my asst.)
    Is creating a New Catalog for EACH  shoot the way to go?   (not sure I like this idea)
    Right now everything is in one(1) catalog  ... and it's getting big ... BUT, this allows us to search , and group ... going way back.
    Would be nice to be able to still do this easily, and with what we have already done.
    With our one BIG Catalog ... not sure if two(2) can access this catalog over the Network at the same time?
    Even though we never Edit the Same Folder or Files at the same time.
    Or will that be a problem over a simple Win7 PRO network?
    Thank you,
    HG

    Aloha Bob,
    Saw your link.  thank you.
    At least I don't feel "alone"  LOL
    At this point ... I am looking for a  "cluncky"   Work Around?
    * I was thinking,  Maybe making a copy of  My Cataloge ...
    Deleting ALL the  Folders in LR  ... except for the one's  that  will be worked by the Asst.
    Then moving that file to the  Asst.  Computer.
    * NEXT,  pointing the  Folder that they are working on ... across the Network to the Servers Files.
    * After they work on it:
    *** IS THERE A WAY ...
    * To  take that Cataloge ... and UPDATE  my Main  Cataloge.
    THIS, is the STEP  ... I don't know how to do.
    Can someone Help me with this?
    Step by Step,  because I am clueless ....
    Talking UPDATE of everything worked on ... including   Virtual copys, and  CROPS.
    Thank you,
    HG

  • How the store and retrieval in ServletContext will happen??

    Hello Sir,
    I am developing a chat application thats in Swing & servlets Now I am able to authenticate user and I am using ArrayList to maintain the names of the user globally my storing it in ServletContext
    How to store and retrieve ArrayList from Servletcontext
    And another thing is that we are having personal chat(1-to-1) also. But how to use the thread model is not known to us as we have not faced such a situation before
    So if you could suggest some example code or snippets ot certain links then it would be of great help to us
    Thanks
    Regards
    Monarch

    Hello
    thanks for your reply. Actually we are doing the same thing that u have mentioned in your reply.
    The thing we are trying to do is that when a user is logged in the particular servlet which is responsible for the authentiacation of the user will authenticate the user an then calls method in the Chatter class which is outside the servlet
    The Chatter class declares two mwthods addChatter() and getChatter()
    I am managing the currently logged users in Arraylist using this two mehtods above
    When the first user logs in his entry gets stored at the first position in the arraylist but when other user logs in then his entry overrites the entry of the first user instead of getting stored in the next position.
    The arraylist gets initialized when second user logs in. to overcome this problem i want to store the arraylist into the ServletContext so it will be unique for the whole application and will not get initialized
    So I want to know the process of storing and retrieving the arraylist fro the context
    Hope ull understand me and reply me
    Thanks
    Regards
    Monarch

  • How do I save a pdf as an html file without losing formatting?

    How do I save a pdf as an html file without losing formatting?  My coworker is able to do this on her Adobe 9 by saving to html css 4.0 - I have Adobe 11 and have not been able to save as an html at all without loosing formatting.

    Are the PDF files that you are attempting to Save As HTML tagged?

  • How do I save a PDF as an excel file when the PDF is horizontal. Adobe tries to rotate the page, but the data is entered in an  horizontal format.

    How do I save a PDF as an excel file when the PDF is horizontal. Adobe tries to rotate the page, but the data is entered in an  horizontal format.

    Thanks for the quick reply.  I figured out how to get the desired results by using tagging.  For anyone who may reference this post in the future, I went to "Customize" in the top right corner of Adobe, then selected "Create new tool set...", looked under "accessiblity and found the "tag" option.  Hit ok, tag is added to the toolbar.  Then I highlighted the dataset in the PDF that was relevant to the output format, then clicked "tag", saved as spreadsheet.  Sorry I can't provide more details on how tagging works or if there's a more elegant solution available, but I'm sure one's out there.

  • How do i convert a .pdf to a WORD file?

    How do I convert a .pdf to a WORD file?

    Hi pdfyes,
    Welcome!
    Try going here:
    ExportPDF getting started guide: http://forums.adobe.com/docs/DOC-2412
    Kindest regards,
    Stacy

  • How to store jpeg images in SQL server using NI database Connectivity Toolset. Can anyone please help me in this regard.

    Please tell how to store jpeg images in SQL Server using NI Database Connectivity Toolset.

    http://www.w3schools.com/sql/sql_datatypes.asp
    You setup a field as BLOB and store the binary of the picture there. Depending on the database it can be called differently as you can see in the link, in SQL server there's even a Image datatype.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

Maybe you are looking for