Application Object In Servlets

First off, I'm new to writing servlets so forgive my ignorance...
How do I get the application object within the init method of an HttpServlet? I want to call some methods on it (e.g. getRealPath) but I get compile errors because I'm not sure how to get the application object.

public void init(ServletConfig config) {
  ServletContext sc = config.getServletContext();
  String path = sc.getRealPath("/"); // or something like that
}

Similar Messages

  • How to get an ArrayList Object in servlet from JSP?

    How to get an ArrayList Object in servlet from JSP?
    hi all
    please give the solution for this without using session and application...
    In test1.jsp file
    i am setting values for my setter methods using <jsp:usebean> <jsp:setproperty> tags as shown below.
    After that i am adding the usebean object to array list, then using request.setAttribute("arraylist object")
    ---------Code----------
    <jsp:useBean id="payment" class="com.common.PaymentHandler" scope="request" />
    <jsp:setProperty name="payment" property="strCreditCardNo" param="creditCardNumber" />
    <%-- <jsp:setProperty name="payment" property="iCsc" param="securityCode" /> --%>
    <jsp:setProperty name="payment" property="strDate" param="expirationDate" />
    <jsp:setProperty name="payment" property="strCardType" param="creditCardType" />
    <%--<jsp:setProperty name="payment" property="cDeactivate" param="deactivateBox" />
    <jsp:setProperty name="payment" property="fAmount" param="depositAmt" />
    <jsp:setProperty name="payment" property="fAmount" param="totalAmtDue" /> --%>
    <jsp:useBean id="lis" class="java.util.ArrayList" scope="request">
    <%
    lis.add(payment);
    %>
    </jsp:useBean>
    <%
    request.setAttribute("lis1",lis);
    %>
    -----------Code in JSP-----------------
    In testServlet.java
    i tried to get the arraylist object in servlet using request.getAttribute
    But I unable to get that arrayObject in servlet.....
    So if any one help me out in this, it will be very helpfull to me..
    Thanks in Advance
    Edward

    Hi,
    Im also facing the similar problen
    pls anybody help..
    thax in advance....
    Litty

  • The "application" object

    the "application" object can be called within a JSP file.
    What if I wanna call it within a JavaBean class? How do I instantiate it?

    The application object is the servletcontext that is passed to the servlet/JSP by the server during initialization. If you want to use it in a JavaBean you'll have to pass it in.
    <jsp:useBean id="myBean" scope="session" class="beans.MyBean" />
    <% myBean.setApplication(application); %>
    and in MyBean
    import javax.servlet.*;
    public class MyBean {
       ServletContext sc;
       public MyBean() { }
       public void setApplication(ServletContext inSC) { this.sc = inSC; }
    }

  • Extracting URL From Application Object

    If I type http://mymachine.com/myapp?a=aaa&b=bbb in my browser (to access application "myapp") how do I extract just the http://mymachine.com/myapp part from the application object? I would have figured that the code below would allow me to construct that string but these methods instead return the stuff in comments...
    URL theURL = application.getResource("/");
    theURL.getProtocol(); // jndi
    theURL.getHost(); // null
    theURL.getPort(); // -1
    theURL.getFile(); // org.apache.naming.resources.FileDirContext@!8bf135
    URL theURL = application.getResource("/myapp");
    theURL.getProtocol(); // null pointer exception
    theURL.getHost(); // null pointer exception
    theURL.getPort(); // null pointer exception
    theURL.getFile(); // null pointer exception

    tech note... HttpUtils is depricated for newer Servlet APIs (2.3+). Instead, you would use the same methods in the HttpServletRequest:
    URL theURL = new URL(request.getRequestURL().toString());

  • Invalid method "Save As" from Excel application object

    I have Windows 2000 and Excel 2002 installed on my machine.
    I down loaded "renamed Excel 2000 workbook.vi" from NI website. Relinked ref num to Excel application object but get the error of invalid method (Save As). Tried to relink invoke node to Save As by selecting method from drop down menu. However this method is not on the list. Tried other excel objects but can not find "Save As" method. Has this been removed/moved?

    I was able to correct the error by relinking the Workbooks->Open to Open. This changes the subsequent Invoke Node from IAppEvents to _Workbook. There you will find the Save As method.
    Michael
    www.abcdefirm.com
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • How to Use AccessibleObjectFromWindow API in VBA to Get Excel Application Object from Excel Instance Window Handle

    I need to get the Excel.application object from a window handle using AccessibleObjectFromWindow. I can't seem to make the code work. First, I successfully search for the XLMAIN windows. Then, when I get a handle, I execute the AccessibleObjectFromWindow
    function. It seems to return a value of -2147467262 in all cases. Therefore, I believe that it is returning an error value. I can't figure out how to determine the meaning of this value.
    If it is an error value, I believe that one or more arguments are in error. My best guess at present is that the GUID argument is incorrect. I have tried two GUID values: {00020400-0000-0000-C000-000000000046} and {90140000-0016-0409-0000-0000000FF1CE}.
    I have seen both used in conjunction with OBJID_NATIVEOM. Neither one seems to work. I really would prefer not to use the second one as it has an Excel major and minor version number. I would hate to have to change this code, if a new minor version appeared.
    The attached code has been commented to show which parts have been shown to work and which not. I'm at my wits end and really need help.
    Thanks
    'This module is located in Access 2010, but this is an Excel question.
    Option Compare Database
    Option Explicit
    ' Module-Level Declarations
    'The GetDesktopWindow function and FindWindowEx function work just fine.
    Public Declare Function GetDesktopWindow Lib "user32" () As Long
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) _
    As Long
    'I'm not getting the expected output from this function (see below)
    Private Declare Function AccessibleObjectFromWindow& Lib "oleacc.dll" _
    (ByVal hwnd&, _
    ByVal dwId&, _
    riid As GUID, _
    xlwb As Object)
    Type GUID
    lData1 As Long
    iData2 As Integer
    iData3 As Integer
    aBData4(0 To 7) As Byte
    End Type
    Function ExcelInstances() As Long
    ' Procedure-Level Declarations
    ' Value of OBJID_NATIVEOM verified by checking list of Windows API constants _
    on this site: http://www.lw-tech.com/q1/base.htm
    Const OBJID_NATIVEOM = &HFFFFFFF0
    Dim hWndDesk As Long 'Desktop window
    Dim hWndXL As Long 'Child window
    Dim objExcelApp As Object 'Final result wanted: Excel application object
    'Following variable (xlapp) to be set by AccessibleObjectFromWindow function
    Dim xlapp As Object
    Dim IDispatch As GUID 'GUID used in call to AccessibleObjectFrom Window function
    'Set up GUID to be used for all instances of Excel that are found
    Dim tmp1 As Variant 'Return value from AccessibleObjectFromWindow
    ' Executable Statements
    SetIDispatch IDispatch
    IDispatch = IDispatch
    'Get a handle to the desktop
    hWndDesk = GetDesktopWindow 'This seems to work
    Do
    'Get the next Excel window
    'The following statement seems to work. We are finding and counting _
    correctly all the instances of Excel. hWndXL is non-zero for each _
    instance of Excel
    hWndXL = FindWindowEx(GetDesktopWindow, hWndXL, "XLMAIN", vbNullString)
    'If we got one, increment the count
    If hWndXL > 0 Then
    'This works. We correctly count all _
    instances of Excel
    ExcelInstances = ExcelInstances + 1
    'Here is the problem. The following statement executes and returns a value of _
    -2147467262. xlapp, which is passed by reference to AccessibleObjectFromWindow, _
    is set to nothing. It should be set to the object for Excel.application. _
    I believe that this value is not an object. I tried to reference tmp1. in the _
    immediate window. There was no Intellisense.
    'I think that the function in returning an error value, but I can't figure _
    out what it is. I believe that AccessibleObjectFromWindow returns error _
    values, but I don't know where to find their values so I can interpret the _
    function's results.
    'As best I can tell, the hWndXL parameter is correct. It is the handle for _
    an instance of Excel. OBJID_NATIVEOM is set correctly (see constant declaration _
    above). xlapp is passed by reference as a non-initialized object variable, which _
    will be set by AccessiblObjectFromWindow. IDispatch may be the problem. It is set _
    as shown below in the procedure SetIDispatch(ByRef ID As GUID). This procedure _
    appears to work. I can see that IDispatch is set as I intended and correctly _
    passed to AccessibleObjectFromWindow.
    tmp1 = AccessibleObjectFromWindow(hWndXL, OBJID_NATIVEOM, IDispatch, xlapp)
    'Need to write code to test tmp1 for error. If none, then set objExcelApp = _
    object. Also, I exect xlapp to be set to Excel.application
    End If
    'Loop until we've found them all
    Loop Until hWndXL = 0
    End Function
    Private Sub SetIDispatch(ByRef ID As GUID)
    'Defines the IDispatch variable. The interface _
    ID is {90140000-0016-0409-0000-0000000FF1CE}.
    'NOT USING {00020400-0000-0000-C000-000000000046}, _
    which could be the problem
    '9 is release version - first version shipped (initial release)
    '0 is release type - retail/oem
    '14 is major version
    '0000 is minor version
    '0016 is product ID - MS Excel 2010
    '0409 is language identifier - English
    '0 is x86 or x64 - this is x86
    '000 reserved
    '0 is debug/ship
    '000000FF1CE is office family ID
    With ID
    .lData1 = &H90140000
    .iData2 = &H16
    .iData3 = &H409
    .aBData4(0) = &H0
    .aBData4(1) = &H0
    .aBData4(2) = &H0
    .aBData4(3) = &H0
    .aBData4(4) = &H0
    .aBData4(5) = &HF
    .aBData4(6) = &HF1
    .aBData4(7) = &HCE
    End With
    End Sub
    DaveInCalabasas

    I don't think you can return a reference to Excel's main window like that as you are attempting to do.
    Ref:
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd317978(v=vs.85).aspx 
    It's relatively straightforward to return any workbook's window in any given instance, and in turn it's parent Excel app. Try the following and adapt as required (and include error handling) -
    Option Explicit
    Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long
    Private Declare Function IIDFromString Lib "ole32" _
    (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
    Private Declare Function AccessibleObjectFromWindow Lib "oleacc" _
    (ByVal hWnd As Long, ByVal dwId As Long, ByRef riid As GUID, _
    ByRef ppvObject As Object) As Long
    Private Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(7) As Byte
    End Type
    Private Const S_OK As Long = &H0
    Private Const IID_IDispatch As String = "{00020400-0000-0000-C000-000000000046}"
    Private Const OBJID_NATIVEOM As Long = &HFFFFFFF0
    Sub test()
    Dim i As Long
    Dim hWinXL As Long
    Dim xlApp As Object ' Excel.Application
    Dim wb As Object ' Excel.Workbook
    hWinXL = FindWindowEx(0&, 0&, "XLMAIN", vbNullString)
    While hWinXL > 0
    i = i + 1
    Debug.Print "Instance_" & i; hWinXL
    If GetXLapp(hWinXL, xlApp) Then
    For Each wb In xlApp.Workbooks
    Debug.Print , wb.Name
    Next
    End If
    hWinXL = FindWindowEx(0, hWinXL, "XLMAIN", vbNullString)
    Wend
    End Sub
    'Function GetXLapp(hWinXL As Long, xlApp As Excel.Application) As Boolean
    Function GetXLapp(hWinXL As Long, xlApp As Object) As Boolean
    Dim hWinDesk As Long, hWin7 As Long
    Dim obj As Object
    Dim iid As GUID
    Call IIDFromString(StrPtr(IID_IDispatch), iid)
    hWinDesk = FindWindowEx(hWinXL, 0&, "XLDESK", vbNullString)
    hWin7 = FindWindowEx(hWinDesk, 0&, "EXCEL7", vbNullString)
    If AccessibleObjectFromWindow(hWin7, OBJID_NATIVEOM, iid, obj) = S_OK Then
    Set xlApp = obj.Application
    GetXLapp = True
    End If
    End Function
    Note as written if an instance does not have any loaded workbooks a reference will not be returned (though a workbook can be added using DDE, but convoluted!)
    FWIW there are two other very different approaches to grab all running Excel instances though something along the lines of the above is simplest.
    Peter Thornton

  • Error 1603 in deploying Office 2003 by creating an application object using its MSI package!

    Hello,
    I got the error of 1603 when I ran Office 2003 MSI package through NAL. I
    have no idea how to resolve this problem. Even though I enabled logging in
    Office 2003 installation, I still could not figure out what went wrong and
    what caused the error.
    I have used Snapshot to create an application object for a long time with
    little problem. However, I could not successfully deploy any MSI package
    created by an application object. I knew ZenWork Managing Application has
    the feature, but I don't know how to make it work in our environment.
    Do I have to know more about Microsoft Window Installer ?
    Appreciate your comments and experience in advance
    Thanks
    Joe Liu
    email: [email protected]

    [email protected],
    > I got the error of 1603 when I ran Office 2003 MSI package through NAL
    >
    Start here:
    http://support.novell.com/techcenter...tation&x=0&y=0
    Yes, understanding MSI helps. FWIW I have deployed 2003 this way.
    - Anders Gustafsson, Engineer, CNE6, ASE
    NSC Volunteer Sysop
    Pedago, The Aaland Islands (N60 E20)
    Novell does not monitor these forums officially.
    Enhancement requests for all Novell products may be made at
    http://support.novell.com/enhancement
    Using VA 5.51 build 315 on Windows 2000 build 2195

  • How to create Illustrator COM application Object  in Invisible manner?

    Hi,
    I added CS6 COM reference in my VB.NET application and after that I have the following basic object creation in order to convert a eps file to svg. But for some reason when I create this COM object it is launching the Adobe Illustrator application. Why it is doing like this? It’s a simple COM object why it is interacting with Illustrator Editor?  Could you guide me how to take care this issue please?
    Thanks
    SG

    I am going to post a reply here from our other posts... http://forums.adobe.com/message/4692998#4692998
    your last post from other message:
    Let’s forget about VB part, even in Java script how do we create the Illustrator instance without bring Illustrator IDE up when you create the application object. It’s a COM component right, why would it bring up the UI? Do you have any simple example in Javascript please?
    To the best of my knowledge in order to access the Illustrator object model that the application must be running through JavaScript since scripts are run via the UI.
    I did find this in the documentation in refference to VB.
    CreateObject launches Illustrator as an invisible application if it is not already running. If Illustrator is
    launched as an invisible application you must manually activate the application to make it visible:
    Set appRef = CreateObject("Illustrator.Application")
    So instead of "As New" try "CreateObject"...
    Just a guess really

  • Access jsp's application object from an .java file?

    Hi,
    I hava a .jsp page and an import statement to a .java file. How can I access the application object in this .java file?
    I want to make an initialization function that I want to be called in every .jsp of the WEB application and to store this function in a .java file.

    The only way to get a hold of the application object would be to pass it to java code as a parameter to a method.
    ie public class Util{
    public void initialiseJSPPage(ServletContext application){
      // do stuff in ServletContext
    }and then in the JSP call it via
    <% Util.initialiseJSPPage(application); %>
    You could manually include this code on every JSP.
    A better alternative is that in web.xml you can configure an automatic include (See JSP.3.3.5)
    What is it you are trying to accomplish by doing this?
    Would a Filter be a more appropriate tool in this case? That would let you run java code before selected requests are handled.
    Cheers,
    evnafets

  • Report by Application Object Name

    have zen7sp1ir1
    i want to generate a report, by application object name, if it is
    distributed to the workstation. ( sucssess failed etc )
    is it possible to do so? how ?
    helge

    Helge,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Visit http://support.novell.com and search the knowledgebase and/or check all
    the other self support options and support programs available.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://support.novell.com/forums)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://support.novell.com/forums/faq_general.html
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • IDOC - process code with error "Application Object Type not planned'

    Hi all,
    I am doing an inbound idoc.... in TCODE we42, i trying to put function module which i created, attached to the process code.
    However, when i put my function module ZIDOC_INBOUND to the process code... it comes out error, 'Application Object Type not planned.'
    Why is this so?
    Please advice...
    Thanks and regards...
    William Wilstroth

    HI all,
    I had solved this problem. I should have gone to we57 to tie the function module.
    thanks.
    William Wilstroth

  • Application object content search across multiple (many) objects

    Hi guys,
    I have about 500 application objects and one of these is pushing through
    a bad registry setting.
    I know what the setting is, but how do I search across all of them quickly.
    Thank you,

    The easiest thing to do is to search c:NALCACHE for the string desired.
    I don't have ZEN at my current location so I can't be 100% sure, but I
    believe much of the info in these cache files is stored in pseudo
    english so a search may work.
    The info is stored in DS in a manner that is less easily retrievable.
    (I.E., Pull up DSReports and browse the object, you will not see all of
    the entries.)
    As I am thinking, at my last job I ran a nightly routine that exported
    all apps to AOTs using the ZFD3 toolkit and than ran another tool from
    the kit to convert the AOTs to AXTs. Then I could do an easy file find
    on all of my apps. The list of apps was generated using a tool from
    JRBSoftware. I don't have the script anymore, but is you are skilled at
    scripting, that may give you an idea for something that my become a
    multi-purpose tool for you.
    chebarushka wrote:
    > Hi guys,
    >
    > I have about 500 application objects and one of these is pushing through
    > a bad registry setting.
    >
    > I know what the setting is, but how do I search across all of them quickly.
    >
    > Thank you,
    Craig Wilson
    Novell Product Support Forum Sysop
    Master CNE, MCSE 2003, CCN

  • Objects through servlet

    How to pass the object through servlet?

    I can venture a guess that the OP wants to 'send' an object as a request parameter or a form field.
    You'd have to turn the object into some data representation that can later on be translated back into the object; serialization comes to mind. It might be easier to just send the properties of the object as seperate request/form fields though!

  • Random application object lost in Portal

    Hi people,
    I'm having a problem with the application object.
    Some times, in a random way, i'm losing the state of the application object between request's.
    This appens when I'm using the BSP application in the SAP Portal.
    Thanks,
    Paulo Ruivo

    Hi,
    the problem is that in the url I pass a parameter that in the bsp page copy to an attribute of the application.
    Then in the controler i try to read this value and it is empty, all the information in application object is lost.
    This appens during one single request.
    I have several Iviews pointing to the same BSP application, the diference between the content that is shown is controled by the parameter passed in the URL.
    Is it possible that while navigating between iviews, the info in the BSP application is mix up. Something like the aplication start (iview open) and then been close (previous iview close)?
    Thanks for the help.
    Paulo Ruivo

  • Outlook.Application Object

    Hello Experts,
    i am using the 'Outlook.Application' object to create a new outlook email item in my ABAP code. everything is fine except when i'm creating an attachment, i don't know how to attach a file to my email. My code look like this.
    REPORT  ztest_outlookobject           .
    INCLUDE ole2incl .
    DATA: lr_outlook TYPE ole2_object,
          lr_mi TYPE ole2_object,
          lr_at TYPE ole2_object.
    CREATE OBJECT lr_outlook 'Outlook.Application'.
    CALL METHOD OF lr_outlook 'CreateItem' = lr_mi
    EXPORTING #1 = 0.
    GET PROPERTY OF lr_mi 'Attachments' = lr_at.
    CALL METHOD OF lr_at 'Add' = 'C:\eraseable.xls'. "<<< the problem is here >>>
    SET PROPERTY OF lr_mi 'To' = 'Bai Cil'.
    SET PROPERTY OF lr_mi 'CC' = '[email protected]'.
    SET PROPERTY OF lr_mi 'Subject' = 'Your subject'.
    SET PROPERTY OF lr_mi 'Body' = 'Some text'.
    CALL METHOD OF lr_mi 'Display'.
    FREE OBJECT lr_outlook.
    but i'm getting this error: "'C:\eraseable.xls'" cannot be changed. -
    Thanks

    thanks guys.
    i found the answer. here it is.
    CALL METHOD OF lr_at 'Add'
    EXPORTING #1 = 'C:\eraseable.xls'.

Maybe you are looking for

  • Urgent - Form hangs

    Hello, I am new to Application Express. I developed couple of forms. Both were working fine until yesterday. All of a sudden my second form just hange when I try to run. I looked into all the queries that run at OnLoad. I tuned them and they run fine

  • Executable behaving different when called f/Java

    I have an executable that is run from the command line which behaves differently when I run it from my application. The executable takes MP3s files as arguments and merges them together. When I use large files from within my app, it doesn't respond,

  • Reboot Necessary for Airport Disk after Sleep

    Anytime one of the computers on the network sleeps, it loses its conneection with the Airport Disk (250GB LaCie), Although the disk appears in the Menu bar icon, attempting to re-connect generates an error message about bad ID and/or Log-in disabled.

  • How To Move Artist Heading To Far Left

    I am wondering how I can move the "Artist" heading in iTunes to the far left. I have tried left clicking and this only lists the columns available. Currently I have the song name in the far left column and I would rather have the "Artist" column ther

  • Hot & Loud - Left Fan staying at over 6000RPM

    For about a week or more now I've notice my MBP being extra loud and extra hot. I did have an issue with an errant app (APC PowerChute) that was maxing out one core. I uninstalled it and it did improve, both fans no longer stayed on and the temp no l