Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:26:56+00:00 2026-05-15T16:26:56+00:00

I just got my hands on doing dynamic web programming using JSP. What is

  • 0

I just got my hands on doing dynamic web programming using JSP. What is the proper way to handle the configurations?

For example, database name, host, login, and password, and indexing directory in the server, etc. My concern is mostly about the security of the passwords. Currently I hard code the data into the .java files, I don’t think this is the right way to do so I would like to learn from your experiences.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:26:57+00:00Added an answer on May 15, 2026 at 4:26 pm

    Configuration is usually stored in a properties or XML file which is been placed in the application’s runtime classpath or at a fixed location which is specified as a VM argument. A properties file can be accessed using java.util.Properties API. A XML file can be parsed using JAXP or JAXB.

    Here’s an example of such a properties file:

    jdbc.url = jdbc:mysql://localhost:3306/javabase
    jdbc.driver = com.mysql.jdbc.Driver
    jdbc.username = java
    jdbc.password = d$7hF_r!9Y
    

    Assuming that it’s named config.properties and it’s been placed in the root of the classpath (or its root path is been added to the classpath), here’s how you could load it from the classpath:

    Properties properties = new Properties();
    properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
    String url = properties.getProperty("jdbc.url");
    String driver = properties.getProperty("jdbc.driver");
    String username = properties.getProperty("jdbc.username");
    String password = properties.getProperty("jdbc.password");
    // ...
    

    Here’s an example of a XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <jdbc>
            <url>jdbc:mysql://localhost:3306/javabase</url>
            <driver>com.mysql.jdbc.Driver</driver>
            <username>java</username>
            <password>d$7hF_r!9Y</password>
        </jdbc>
    </config>
    

    Assuming that it’s called config.xml and it’s been placed in the root of the classpath, here’s an example how you could load it by JAXP:

    InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.xml");
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(input));
    XPath xpath = XPathFactory.newInstance().newXPath();
    String url = (String) xpath.compile("//config//jdbc//url").evaluate(document, XPathConstants.STRING);
    String driver = (String) xpath.compile("//config//jdbc//driver").evaluate(document, XPathConstants.STRING);
    String username = (String) xpath.compile("//config//jdbc//username").evaluate(document, XPathConstants.STRING);
    String password = (String) xpath.compile("//config//jdbc//password").evaluate(document, XPathConstants.STRING);
    // ...
    

    It’s only a bit more verbose although JAXB can make life easier if it’s a rather complex file.

    Securing the access to properties or XML files in turn is to be controlled at higher (OS/platform) level.

    See also:

    • Properties tutorial
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the recent hype over iPhone App programming, I got my hands on a
I've got a many-to-many relationship in my database and I'm using Hibernate to retrieve
Just got the new iPad, and when I touch the microphone and say a
i just got a call from Hosting company, they claimed that my application creates
I just got an email from twitter saying my keys have now been enabled
I just got pagination to work on my site, but I wanted to use
I just got a job offer to be a FE Developer, but I've never
I just got out of a small project and I've tried to follow a
We just got our first major Perl CGI assignment in my CS class. Our
I just got setup on my first Windows Server 2008 / IIS7.5 server for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.