5 Replies Latest reply: Nov 19, 2012 3:00 PM by OAF_Monkey RSS

    how to create a Servlet

      Hello All,

      I am trying to learn creating a servlet in oaf. Although I kind of understand the concept of a servlet....have doubts about where the servlet class file lives/resides? Does it matter where it resides....at least for now in the Jdeveloper environment?

      The way I understand it is:
      1) In the oaf page need to place the item in which the servlet result is displayed
      2) In the PR of the CO of the above page, need to find the above item
      2.1) set the source of the above item to be the servlet class while passing in the params into the set source call.
      2.2) Does it matter where the servlet class file resides? ie., can it live anywhere in the project??

      Pls. help me understand this concept.

      Practially in steps2,3 of the servlet wizard of the Jdeveloper what do these do?
      Step#2: URL Pattern
      Step#3: Parameters. Do I have to necessarily set up the params here in this step or can they be dynamically set when the serveletis invoked in the PR of the CO? If yes, could you pls. provide a sample code. If params can be done either way...which way is effective. Reason for asking is....in my other post, I mentioned that while trying to create a dynamic VO, it seemed to force me to explicitly set the sql statement instead of simply running the sql statement associate with the VO of the page (I am not sure why it is like that...but that worked)


      Edited by: OAF_Monkey on Nov 16, 2012 4:11 PM
        • 1. Re: how to create a Servlet

          Any help here?

          • 2. Re: how to create a Servlet
            Sushant Sharma

            What is your requirement and why do u want to create a servlet in oaf ?

            You can create a jsp file.. which will end up in a servlet and u hv to place that at OA_HTML.

            • 3. Re: how to create a Servlet
              Trying to display image (blob colum in the table) in the oaf page (as a column in the table region of the oaf page...to be more specific)

              trying to follow the below link:

              [ [https://forums.oracle.com/forums/thread.jspa?messageID=918300|https://forums.oracle.com/forums/thread.jspa?messageID=918300]]

              Some how not working....all I see is a red "x" in the column where the image is supposed to show.

              Not entirely sure how each piece fits conceptually...ie., as mentioned in the above link, I have the
              1) "Readimage" jave file in the same pkg as the 'PG' files
              2) If look in the "web.xml" (which by the way is located under "WEB-INF" folder under "OA_HTML", there is an entry for my "Readimage". That entry is shown below:

              Edited by: OAF_Monkey on Nov 19, 2012 10:52 AM
              • 4. Re: how to create a Servlet
                The way I understand (after following several older posts) is
                1) When my destination page (say page2 renders), in the CO need to find the image item/bean (I am assuming bean and an item mean the same)
                2) After finding the item item/bean, need to set its source as "ReadImage" telling it to go get it from the web.xml while passing in the id
                for which it needs to find an image/blob in the db.

                At this point, if it finds the class "ReadImage" then it should get the
                2.1)db connection
                2.2)get the parameter passed in using
                      String image_id = request.getParameter("s1");
                2.3)get the sql statement provided
                2.4)get the image/blob as an input stream and write to the output stream using the below
                        InputStream in = null; 
                        in = rs.getBinaryStream("IMAGE"); 
                Below is my code in the PR of CO
                      System.out.println("I am back in the IMG CO : primaykey val is "+ s1 );
                 BP1-->  OAImageBean imageItem = (OAImageBean)webBean.findIndexedChildRecursive("SJImage");
                      System.out.println("I am back in the IMG CO1 : after finding the image item" );
                 BP2-->     if (imageItem !=null ){
                      System.out.println("I am back in the IMG CO2 : before setting the source of the image item" );     
                 BP3-->     imageItem.setSource("/OA_HTML/WEB-INF/ReadImage?id=" + s1);
                      System.out.println("I am back in the IMG CO3 : after setting the source of the image item" + imageItem.getSource());
                When I ran it in the debug mode (break points shown above BP1,2,3), I can see that the value is getting passed in ok with the 's1' at BP1 and BP2.
                However when it reaches BP3, if I expand all the nodes of the debug window, I can see that in the 'Statisfields of the CO', it shows
                "Failed to establish the database connection." for the "DBCONNECT_ERROR_MSG" node.

                In the "ReadImage" class file the code to get connection is shown below:
                    public void init(ServletConfig config) throws ServletException {
                        catch (Exception exception ) 
                        throw new UnavailableException(exception.getMessage()); 
                In the doPost method:
                        if (conn == null)
                        WebAppsContext ctx = null;
                        ctx = WebRequestUtil.validateContext(request, response);
                        ctx = WebRequestUtil.createWebAppsContext(request, response);
                        conn = ctx.getJDBCConnection();
                        stmt = conn.createStatement();
                Is this code correct to get a db connection? Pls. share thoughts/ideas/suggestions...

                • 5. Re: how to create a Servlet
                  I seem to have gotten stuck here....any suggestions/help from gurus who have accomplished displaying a blob in an oaf page? Pls. help!