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)
Thanks,
Edited by: OAF_Monkey on Nov 16, 2012 4:11 PM

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 {
        super.init(config);
        try
        Class.forName("oracle.jdbc.driver.OracleDriver");
        catch (Exception exception )
        exception.printStackTrace();
        throw new UnavailableException(exception.getMessage());
    }In the doPost method:
        if (conn == null)
        try
        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...
Thanks,

Similar Messages

  • How to create the servlet as acontroller  and how to use it

    how to create the servlet as acontroller and how to use it

    >
    John
    Please update your forum profile with a real handle instead of "914824".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I am going to have over 50 buttons in a page, Why? This would be a most unusual UI paradigm. I've never seen such a page, which suggests that whatever you want to do is normally done another way. Please explain the requirement in more detail.
    just wanted to know if its possible to do something like this in java.
    Java is not used in programming APEX UI behaviour. Java and JavaScript may share initial syllables, but they are not closely related.
    It's possible to achieve a great deal in JavaScript, but a clear definition of the requirements is necessary. Do you mean the buttons should be dynamically generated? If so, yes, this is possible in JavaScript. What would drive the process?
    Also, i would like to have dynamic action on it, for example, when the button is pressed, fill a string of text into other items(text field) within the page. Without more detail its not possible to make any specific suggestions. For example, I certainly would not want to create 50+ individual dynamic actions relating to different buttons.

  • How to create a servlet  in PAR Application

    Hi Experts,
    I want to create a servlet in PAR application. This servlet should be capable of accessing the functions of other java files included in PAR Application. Servlet should be capable of accessing the functions say doContent(req, resp) of any class of PAR application.
    Is it possible to create Servlet in PAR application?
    I created one servlet but unable to declare its information in Deployment Descriptor.
    Because the deployment which is provide ie portalapp.xml doesnt allow us to write tags like <servlet-name>, <servlet-mapping>, <url-pattern> etc. These are necessary for declaration of servlet.
    So how can i write a complete working Servlet under PAR application?
    Please help and replies will be appreciated.

    Hi,
    Depending upon your usecase there are different ways to implement this logic.
    Check this for example (Read my answer in this post):
    https://forums.sdn.sap.com/thread.jspa?threadID=349151
    Also check these senarios:
    http://help.sap.com/saphelp_nw70/helpdata/en/42/9ddf20bb211d72e10000000a1553f6/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/42/9ddcc9bb211d72e10000000a1553f6/frameset.htm
    Also the delegation may be interesting for you:
    http://help.sap.com/saphelp_nw70/helpdata/en/a0/44b742cafec96ae10000000a155106/frameset.htm
    Greetings,
    Praveen Gudapati

  • How to create a servlet and write its details in DD in PAR Application

    Hi Experts,
    I want to create a servlet in PAR application. This servlet should be capable of accessing the functions of other java files included in PAR Application. Servlet should be capable of accessing the functions say doContent(req, resp) of any class of PAR application.
    Is it possible to create Servlet in PAR application?
    I created one servlet but unable to declare its information in Deployment Descriptor.
    Because the deployment which is provide ie portalapp.xml doesnt allow us to write tags like <servlet-name>, <servlet-mapping>, <url-pattern> etc. These are necessary for declaration of servlet.
    So how can i write a complete working Servlet under PAR application?
    Please help and replies will be appreciated.

    Hi Pankaj,
    I don't think it is possible to write Servlet in portal applications.
    I guess in Portal Application Projects we can develop portal components and portal services only.
    Thanks and regards,
    -Madhu

  • How to create a servlet to be called by a portlet in weblogic workshop

    Hey,
    In weblogic workshop 8.1.4, I created a portal application. In the portlet(Java portlet- JSR 168), I would like to call a Java Servlet. In the workshop, it seems there is no way to create a Java Servlet.
    Does anybody know how to create a Java Servlet in the Weblogic workshop?
    Thanks!
    Jeff

    How about creating a java class and adding the proper imports, extends, methods etc. to make it a servlet.
    Do the the necessary changes to web.xml
    Then try to invoke it from the portlet's jsp of java code
    HTH,
    Raj

  • How to create a Servlet Exception in jsp

    Greetings,
    I would like to know if someone knows how create a servlet exception in a JSP.
    Thx

    What for? new ServletException() - IIRC it's not abstract.

  • [Deploy Tool] How to create a  Servlet?

    Hello,
    i try to assemble and deploy a java servlet with the deploy tool in NW4, but to no avail. I managed to use jsps succesfully, but up to now i failed with servlets.
    When i try to access the WAS after deploying my exercise, i get:
    <b>404 Requested resource ( Ue160/servlet/Login.class ) not found.</b>
    The file Login.class, the directory /servlet and the URL mapping are defined in the file tab of 'J2EE Components'. As far as i can see the servlet container is unable to load the class file.
    The servlet name is in red, so something is wrong. But i can build the war-file without any error messages.
    Any hints?
    I can't use the developer studio, because it does not work with NW4.
    Message was edited by: Nico Manicone

    hi jeff
    1. I am not aware of any portal specific screen which can create this screen for you. However to create a servlet you will need to extend from the HttpServlet interface
    2. To direct the request to your servlet from your jsr 168 portlet you could use the PortletRequestDispatcher getNamedDispatcher(String s) declared on PortletContext
    Hope this helps
    anand

  • How to Create an XML document from XSQL servlet which follows a particular DTD struct

    how to Create an XML document from XSQL servlet which follows a particular DTD structure.Could anyone send me a sample code for this.

    You'll need to associate an XSLT transformation with your XSQL page that transforms the canonical result into your DTD-valid format.
    For example, given an XSQL page like:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="rss.xsl" ?>
    <xsql:query max-rows="3" connection="demo" xmlns:xsql="urn:oracle-xsql">
    select title,id,description,url,to_char(timestamp,'Mon DD') timestamp
    from site_entry
    order by id desc
    </xsql:query>and an "rss.xsl" stylesheet that looks like this:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" doctype-system="rss-0.91.dtd"/>
    <xsl:template match="/">
    <xsl:for-each select="ROWSET/ROW">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    <xsl:for-each select="ITEM">
    <item>
    <title><xsl:value-of select="TITLE"/></title>
    <link><xsl:value-of select="URL"/></link>
    <description><xsl:value-of select="DESCRIPTION"/></description>
    </item>
    </xsl:for-each>
    </channel>
    </rss>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>You produce DTD-valid output against the rss-0.91.dtd DTD that looks like:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE rss SYSTEM "rss-0.91.dtd">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>

  • How to create own server account for servlet application

    hi friends..
    i have created a servlet page which recieve some data from a j2me program..
    i am running this aplication on my pc using http://localhost:8080/mypage
    now i want to deploy my j2me program on my mobile phone and need to get data in my servlet page
    for this i need to create my own server account for apache but i dont know how to create my own sserver account
    please help me out if anyone knows it how to do it...
    thanx
    kiran_arora

    if you want to create your own webitem check out the link given by other sdner.
    if you want to be able to execute BW query using abap you can check out the following weblog.
    /people/durairaj.athavanraja/blog/2005/12/05/execute-bw-query-using-abap-part-iii
    Regards
    Raja

  • Is anyone know how to create dynamic pdf file from a JSP page or Servlet ?

    Hi
    Is any one know how to create a dynamic PDF file from JSP or servlet. I need to have standard form format needs to be created and want to send the info to that form dynamically.
    Is there any libraries available?
    Thanks

    I posted a link in this thread to a lib that lets you create PDFs from an app. They have a Java version. I have not used it but I know someone who used it with Microsoft ASP and they liked it.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=287285
    -S-

  • How to create session in JSP & Servlet

    Hi All
    I'm really new to JSP & Servlet. So I want to know how to create sessions and how to pass details to another web page
    Thanks
    Padma

    You can easily pass objects from one jsp or servlet to another.
    On your servlet execute method (for example), you can do this as follows:
    HttpSession session = request.getSession();
    User u = new User();
    session.setAttribute("user", u);And get it again on other servlets:
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");I hope this helps you.

  • How do i create a servlet ?

    How do i create a servlet ?

    Sun has pretty good tutorials. Try this:-
    http://java.sun.com/docs/books/tutorial/servlets/index.html

  • How to Create servlets

    Any One plz guide me how to create a simple Servlet with the help of ECLIPSE3.3

    This may be helpful:
    http://www.java-tips.org/java-tutorials/tutorials/introduction-to-java-servlets-with-eclipse.html

  • How to Create a session in Servlet

    will somone show me the code to create a session in servlet?
    if a session can be created in servlet file, it can be used all the jsp files in a same web ?
    Thanks!!!

    Session in Java web application is started by the web server itself.
    In a servlet you can get the session by
    HttpSession session = request.getSession();
    It will return the current session associated with this request, or if the request does not have a session, creates one.

  • How to create crystal reports using servlets/jsp

    plase any body help me how to create and interact with crystal reports using java

    To use the inproc RAS SDK with CR.NET, you'd have to purchase either (1) Crystal Reports XI Release 2 Developer edition, and apply Service Pack 2 or above, or (2) Crystal Reports 2008 (not Crystal Reports Basic that comes with Visual Studio 2008).
    Sincerely,
    Ted Ueda

Maybe you are looking for

  • When I try and launch Premiere Pro CS6 I get dynamiclinkmanager quit unexpectedly

    And Premiere Pro CC never launches. And the dynamiclinkmanager window keeps coming up, to the point that i can't do anything else as the window just keeps going to the foreground. CS6 all works perfectly fine. I am on a MacPro 4,1 running 10.8.4 with

  • Drag and Drop Listbox: Box 1 to Box 2 then same data dragged back to Box 1

    Right now, I have one listbox (1) with string data that can be dragged to another listbox (2).  However, I cannot take that same string data and drag it back to the original listbox (1). If I try to do that, the string data just disappears and I cann

  • Mapping Drive using Java

    Hi All currently I'm using windows scripting to map a drive. However, I would like to change to using java program to map a drive. Is there any method or class that I can use to map drive???

  • Adobe app manager won't launch

    Hi there, I'm trying to download additional software from the creative cloud.  When the adobe site launchers the app manager on my mac, two red icons bounce - as if loading - then disappear. How to do i get the app manager to launch correctly, or is

  • A fix for a blurry external monitor for the mac air 11

    http://gizmodo.com/5938452/a-trick-to-make-using-an-external-monitor-with-your-m acbook-way-better After a frustrating evening with a blurry external monitor I found the fix at link above. Very happy!