How to get the real path of the application in a JavaBean?

Hi everyone,
I know this has been asked several times before, but I I am not really satisfied with the answers... :-)
I am writing a webapp which uses XML files for storing information, the "business" logic is in JavaBeans. So far I just used hardcoded paths, now I will have to put the thing on a server and need a better solution.
I understand I can use getServletContext().getRealpath() but that doesn't work in a Bean.
One solution would be to fill a (hidden) field calling that and passing the field to the Bean, but I don't really like that solution.
I am using Java Studio Creator 2 (Update 1), isn't there a way to access the ApplicationBean instance in my JavaBeans? As I understand it, I could get the path from there as well.
Thanks!

When you create the bean that contains the business logic you will have to pass in the real path either as a constructor parameter or by setting a property of the bean.

Similar Messages

  • How to get the application path?

    Does some body know how to get the application path in Java? Here is an example about what I'm thinking: Let's imagin the application is on "c:\try" or "c:\ProgramFiles\MyApp". My question is how can I find the path where the application is. Please give an example if you know the answer. Thank you so much.

    Those two replies give you some useful directories, it's true, but maybe not what the OP asked. However the OP asked for something that doesn't have a meaning (applications don't have to be "on" any directory, whatever that might mean).
    Would the OP like to describe what the actual problem is here?

  • How to get the Application perform actions when exits?

    How to get the Application perform actions when user clicks on the "X" icon in the top right hand corner?
    OR
    If i placed an Exit Button.... when actions that i need to use to allow my application to perform a certain action when it exits?
    Thanks

    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        // do your stuff here
    });The WindowListener and WindowEvent can be found in java.awt.event package
    //David

  • HT4623 i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    look at this thread
    https://discussions.apple.com/message/22837309#22837309

  • How to get the Application name/fullpath in a servlet deployed in WebLogic

    Hi ,
    Just like we can get the domain root directory from weblogic.management.DomainDir
    String root = DomainDir.getRootDir() ;and domain name from weblogic.management.configuration.DomainMBean
    DomainMBean domainMBean = MBeanUtils.getDomainMBean();
    String domainName = domainMBean.getName() ;How can i get , the application name in which the servlet is deployed from inside the same servlet ? Which API from weblogic provides that information ?
    for eg : application path = Middleware/user_projects/domains/Domain_1/servers/AdminServer/upload/webapp1.war
    and application name = webapp1.war
    Edited by: Tom on Mar 31, 2011 9:32 PM

    Not sure about Weblogic Specific API however you can use Java API.
    public void init(ServletConfig config) throws ServletException {
              // TODO Auto-generated method stub
              System.out.println(config.getServletContext().getRealPath(""));
              System.out.println(config.getServletContext().getContextPath());
    output:
    C:\Documents and Settings\user\KEDB\KEDBRISKIT\WebContent --- Application Path
    /KEDBRISKIT --- Application Name
    -Akshay

  • How to get the application expose with a mouse

    Hi,
    I want to get a quick overview of all open windows of the SAME application (= application expose). Normally, you can do this with your trackpad (three or four fingers down movement); I am now working with a "normal" (non-Apple) mouse and keyboard. How do I get the application expose with the mouse? I am able to quickly get the misson control wiht CTRL + right mouse click; and I am getting the App expose with shift + arrow down.
    Isn't there a way to get the application expose with the mouse as well? E.g. CTRL + Shift + right click would be very useful but that's taken by the 'slow moving' mission control.
    I know, it's a minor detail but it would be quite good for the workflow
    Any hint is most welcome. Many thanks.

    grab all the code inside the actionPerformed(ActionEvent e) method

  • How to get the application module instance in backing bean.

    This is Ramesh, I am new to JDeveloper world.
    In my current application I have change password screen which allows user to change there password.
    Here this is a pop-up page. Here I don't have the view object and pagadef for this changepassword.jspx file.
    My aim is to call the Application Module method which takes the user name, old password and new password.
    In backing bean I am trying to call this method by using
    MyProjAM obj = _binding.getDataControl().getApplicationModule();  //throw null pointer exception.
    _binding is the object of DCBindingContainer. 
    ( I have created the parameter called "binding" as my managed bean property and values as #{binding})
    But the above line is throwing the NullPointerException.
    Could you please help me to come out of this problem.
    Thanks and Regards,
    Ramesh Biradar.

    If your page has no page definition, then #{bindings} will be null during the request for that page.
    If you need your page to invoke a data control method when you press a button, the simplest (and declarative) way is publish your AM method on the AM's client interface, then drop the method as a button from the data control palette onto your page. You don't even need a backing bean to accomplish this.
    That said, you can refer to a data control in a backing bean using the expression #{data.[i]YourAppModuleNameDataControl.dataProvider}
    So, assuming you have a helper method like this:
      public static Object EL(String expression) {
        FacesContext ctx = getFacesContext();
        Application app = ctx.getApplication();
        ValueBinding bind = app.createValueBinding(expression);
        return bind.getValue(ctx);
      }and assuming that your application module is named SRService
    and assuming that you have correctly nominated any Application Module custom methods as being available to clients by selecting them on the "Client Interface" panel of the application module editor, then in a backing bean you can acquire an instance.
    Then, the ADF design time will have automatically generated you a custom AM client interface named SRService and you can reference that service interface in your backing bean by using code like this:
            SRService svc = (SRService)EL("#{data.SRService.dataProvider}");
            svc.yourCustomMethod(your,args);

  • Not able to get the Application ID value in ADF Phase listener for Custom ADF application which integrates with Ebiz R12.2.3

    Hi All ,
    I am working on one custom Order Mangement ADF Application which integrates with EBiz R12.2.3.
    We are trying to get the Ebiz userid ,username,Responsibility ID and Application ID in ADF through below Code
           public HashMap checkEBSSession(HttpServletRequest request,
                                       HttpServletResponse response) {
            System.out.println("In AMImpl.. checkEBSSession1");
            Session session = null;
            HashMap hmap = new HashMap();
            try {
                Connection conn =
                    getDBTransaction().createStatement(1).getConnection();
                System.out.println("In AMImpl.. checkEBSSession2");
                EBiz ebiz =
                    new EBiz(conn, "012E7E82CD8852BBE053860F6E0AD63413191049361744553610276495342217");
                System.out.println("In AMImpl.. checkEBSSession3");
                AppsRequestWrapper wrapper =
                    new AppsRequestWrapper(request, response, conn, ebiz);
                System.out.println("In AMImpl.. checkEBSSession4");
                session = wrapper.getAppsSession(true);
                System.out.println("In AMImpl.. checkEBSSession5");
                Map columns = session.getInfo();
                System.out.println("In AMImpl.. checkEBSSession6");
                String respId = (String)columns.get("RESPONSIBILITY_ID");
                String currentUserId = (String)columns.get("USER_ID");
                String currentApplId = (String)columns.get("APPLICATION_ID");
                String currentOrgId = (String)columns.get("ORG_ID");
                System.out.println("In AMImpl.. checkEBSSession7...respId : "+respId);
                System.out.println("In AMImpl.. checkEBSSession8...UserId : "+currentUserId);
                System.out.println("In AMImpl.. checkEBSSession9...APPL_SERVER_ID : "+currentApplId);
                System.out.println("In AMImpl.. checkEBSSession10..OrgId : "+currentOrgId);
                logger.info("respid:  " + respId);
                //System.out.println("In AMImpl.. checkEBSSession8");
                hmap.put("RESPONSIBILITY_ID",respId);
                //System.out.println("In AMImpl.. checkEBSSession9");
            } catch (Exception e) {
                System.out.println("Error: " + e.getMessage());
            return hmap;
    By using this code I am Getting all the Information Except the Application ID.
    If someone  have any idea how to get the application ID please share it .
    Thanks in Advance !!
    Thanks & Regards
    Apurv Agarwal

    Hi,
    since you implements the backing bean from PagePhaseListener. some where the same view is excuting before getting the selected record. Even if you select the record after excuteQuery() it will set the first record as selected. Please try to check some where query is excuting.
    try give some more details like what are all the methods you are using in PagePhaseListener and where you worte u r coding.
    Reg,
    Brahma

  • How to get the Real Path of a file which is accessed  by URL?

    iam using tomcat6.0.
    I have a file xyz.xml at the top of the webapplication HFUSE which i can able to access by URL
    http://localhost:8080/HFUSE/xyz.xml
    My problem is how to get the realpath of the file "xyz.xml" for reading and writing purposes.
    I tried various things but i could not able to successfully solved the problem?
    1) File f = new File("/xyz.xml");
    print(f.getAbsolutePath()) ============== it is not fetching the file @ http://localhost:8080/HFUSE/xyz.xml rather it is creating a file
    at the root of the drive where eclipse is running.
    2) File f = new File("xyz.xml");============> this is also not working , it is creating the file xyz.xml in the eclipse directory ..................
    Can anyone please guide on this problem?

    RevertInIslam wrote:
    If you want your context root(i.e HFUSE)
    use this:
    request.getContextPath() //where request is HttpServletRequest object to get the needful path.
    e.g:
    File f = new File(request.getContextPath()+"/xyz.xml");//it will create the file inside HFUSE.
    Hope this helps.
    Regards
    BWrong. The File constructor expects an absolute filesystem path. The HttpServletRequest#getContextPath() doesn't return the absolute filesystem path, it only returns the relative path from the current context root. Use ServletContext#getRealPath() instead, it returns the absolute filesystem path for the given relative path from the current context root.
    File file = new File(servletContext.getRealPath("/"), "xyz.xml");

  • How to get the full path instead of just the file name, in �FileChooser� ?

    In the FileChooserDemo example :
    In the statement : log.append("Saving: " + file.getName() + "." + newline);
    �file.getName()� returns the �file name�.
    My question is : How to get the full path instead of just the file name,
    e.g. C:/xdirectory/ydirectory/abc.gif instead of just abc.gif
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class FileChooserDemo extends JFrame {
    static private final String newline = "\n";
    public FileChooserDemo() {
    super("FileChooserDemo");
    //Create the log first, because the action listeners
    //need to refer to it.
    final JTextArea log = new JTextArea(5,20);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);
    //Create a file chooser
    final JFileChooser fc = new JFileChooser();
    //Create the open button
    ImageIcon openIcon = new ImageIcon("images/open.gif");
    JButton openButton = new JButton("Open a File...", openIcon);
    openButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showOpenDialog(FileChooserDemo.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //this is where a real application would open the file.
    log.append("Opening: " + file.getName() + "." + newline);
    } else {
    log.append("Open command cancelled by user." + newline);
    //Create the save button
    ImageIcon saveIcon = new ImageIcon("images/save.gif");
    JButton saveButton = new JButton("Save a File...", saveIcon);
    saveButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showSaveDialog(FileChooserDemo.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //this is where a real application would save the file.
    log.append("Saving: " + file.getName() + "." + newline);
    } else {
    log.append("Save command cancelled by user." + newline);
    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(openButton);
    buttonPanel.add(saveButton);
    //Explicitly set the focus sequence.
    openButton.setNextFocusableComponent(saveButton);
    saveButton.setNextFocusableComponent(openButton);
    //Add the buttons and the log to the frame
    Container contentPane = getContentPane();
    contentPane.add(buttonPanel, BorderLayout.NORTH);
    contentPane.add(logScrollPane, BorderLayout.CENTER);
    public static void main(String[] args) {
    JFrame frame = new FileChooserDemo();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);

    simply use file.getPath()
    That should do it!Thank you !
    It takes care of the problem !!

  • How to get the SubVI(the virtual path is under .exe) reference in Run Time System

    Hi everyone
    The problem is about how to get the SubVI reference in Run Time System, when the SubVI is in .exe after building.
    More details:
    The top vi calls the SubVI by dynamic way, so the SubVI is included always, and the source object is the application.exe.
    After the setup above, the SubVI will be in the application.exe. For example, SubVI's path is ...\application.exe\SubVI.vi
    So, how to get SubVI's reference in Run Time System?
     I can not get it when using "open VI reference" with the path ...\application.exe\SubVI.vi in Run Time System.
    Actually, I can create a file to include the SubVI, instead of build the SubVI in application.exe , then I can get the reference convenintly. But it is not my favourate way.
    Thanks
    chenyin
    Solved!
    Go to Solution.

    Here is the problem. Call a dynamic subVI means users could change it but it's also very attractive.
    The dynamic call must be used within a user mastered but some parade can avoid problems.
    It depends of why you use dynamic calls... => 2 main ways:
    - Dynamic call are use to maintain an evolutive  part of the code without acting on the executable => one unique VI distribution maintained by the administrator/developer
    - Dynamic call are use to provide a collection of 'external' feature which could be enriched by the administrator/developer. For example, you provide to your customer a set of custom signal filters selectable in the executable.
    In the 2 cases, you are only able to assess user skills to know if there is a risk of damage if there is modification.
    So, to stay alone master a parade could be to provide dynamic VI without diagram but with the problem of maintenance because no modification in situ and more attention to manage distribution.
    An other way is to hide the real distribution to user => call dynamic VI but unnamed it as *.vi but other (a repulsive name as OS system name ) or simply with no extension in order to not  attract user... but it's questionable...
    Another method more difficult but safer is to create a test of consistency ahead of your routine (version, user, modification date, ...)

  • How to get the current path of my application in java ?

    how to get the current path of my application in java ?
    thanks

    To get the path where your application has been installed you have to do the following:
    have a class called "what_ever" in the folder.
    then you do a litte:
    String path=
    what_ever.class.getRessource("what_ever.class").toString()
    That get you a string like:
    file:/C:/Program Files/Cool_program/what_ever.class
    Then you process the result a little to remove anything you don't want:
    path=path.substring(path.indexOf('/')+1),path.lastIndexOf('/'))
    //Might be a little error here but you should find out //quickly if it's the case
    And here you go, you have a nice
    C:/Program Files/Cool_program
    which is the path to your application.
    Hooray

  • For some reason the system is telling me my birth date is wrong when it's not and it won't let me proceed to reset my password. Can someone tell me how to get a "real" person from tech on line?

    For some reason the system is telling me my birth date is wrong when it's not and it won't let me proceed to reset my password. Can someone tell me how to get a "real" person from tech on line?

    contact itunes support

  • How to get the absolute path of logicalhost server domain on Windows Sun

    i am reading a file from Xsql Folder, that is located in the logicalhost Sun\AppServer\domains\domain1\applications\j2ee-apps.(IN Sun Application Server)
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    i tried with System.getProperty("com.sun.aas.instanceRoot").
    but i am able to retrive Sun\AppServer\domains\domain1 upto this .i am unable to retrive Sun\AppServer\domains\domain1\applications\j2ee-apps.
    please suggest me how u can get absolute path in sun application server

    Take a look here

  • How to get the absolute path of logicalhost server domain on Windows?

    My logicalhost server domain behaves strangely. I am reading a file from collaboration definiton, that is located in the logicalhost/is/domains/domain1/config folder. I thought, that this folder is used as an application root folder so I can read files like ./file from there. And it worked.
    But then I've installed the domain as a Windows service, restarted the PC. When the domain1 gets started, I get exceptions saying that the file can't be found. Then I restart the domain (in domainmgr.bat) and it works again.
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    And my second question is: Why does this happen?

    The default folder for a Windows Service is the system32 folder contrary to the instance root folder when starting it as a normal process.
    That's the why, haven't tried the how, but you should be able to get the value by calling System.getProperty("com.sun.aas.instanceRoot").
    Hope this helps
    Paul

  • How to get the pull path name from a file upload window

    Hello everyone!
    I have encountered the following problem with the following JSP code:
    <form method="post" action="filename.jsp">
    Upload JAVA program:
    <input type=file size=20 name="fname" accept="java">
    <input type=submit value="go">
    </form>
    <%
    String s = "";
    if (request.getParameter("fname") != null)
    s = request.getParameter("fname")
    %>
    The value of s is alway the filename. However I want to get the full path in addition to the filename, so that I can read the file. Does anyone know how to get the pull name of the file?
    thanks a lot in advance,

    Dear Sir,
    thanks a lot for your reply. Please let me explain what I intended to do: I want to upload a file from the local machine and then read the content of the file. Therefore I need to the fullpath of the filename like /var/local/file.java instead of file.java. The latter is what I got.
    The problem I have with your code is that the function like "request.getServerScheme()" is not recognized. Maybe is it because I didn't install servelet package? I only installed javax package btw. Also my application runns on Tomcat server if this could give you some information. The error message I had is as follows:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:133: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    url = request.getServerScheme()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:136: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    + ((("http".equals(request.getServerScheme()) && request.getServerPort() != 80)
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:137: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    ||("https".equals(request.getServerScheme()) && request.getServerPort() != 443))
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:139: cannot resolve symbol
    symbol : method getServletConfig ()
    location: interface javax.servlet.http.HttpServletRequest
    + "/" + request.getServletConfig().getServletName()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:140: cannot resolve symbol
    symbol : variable path
    location: class org.apache.jsp.addExercise_jsp
    + "/" + path
    ^
    5 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

Maybe you are looking for