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 7919693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:57:03+00:00 2026-06-03T15:57:03+00:00

In my project I’m using Servlet 3.0 and I’ve tried to use annotations. To

  • 0

In my project I’m using Servlet 3.0 and I’ve tried to use annotations.

To init the connection parameters for the DB I use this in my servlet :

@WebServlet(name = "FrontServlet", urlPatterns = {"/index"},
        initParams = {
        @WebInitParam(name = "userDB", value = "root"),
        @WebInitParam(name = "passwordDB", value = "*****")})

Now when I packaged the project in a WAR I’ve no web.xml so I can’t edit the init parameters as I used to do whith older servlet version.

My question is, can I edit my init parameters when the project is packaged in a WAR? If yes how? Otherwise what approach should I use to store my init parameters and be able to modify them in the WAR?

If possible I would like to avoid to recreate the whole web.xml with all URL-patterns, etc…

EDIT :

Finally I kept :

@WebServlet(name = "FrontServlet", urlPatterns = {"/index"})

And I load DB params using Properties, accessing the config file with getClass().getClassLoader().getResourceAsStream("servlet/config/config.ini")

  • 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-06-03T15:57:04+00:00Added an answer on June 3, 2026 at 3:57 pm

    AFAIK there is no standard way to modify the init params in runtime. Moreover, it’s a bad practice to put configuration there, especially to put there database credentials in a clear text.

    Usually the best practices is to put a configuration in an external file. It may be some custom properties or xml file.

    For database connection it’s common to use JNDI. So basically in the code you look for a JNDI resource, while the JNDI itself in configured at container level. Google to find a lot of examples how to configure database connection via JNDI for Jetty, Tomcat, JBoss and more.

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

Sidebar

Related Questions

Project Euler 126 says: If we then add a second layer to this solid
My project is currently using a svn repository which gains several hundred new revisions
The project is ASP.NET 2.0, I have never been able to reproduce this myself,
project: Using VB.NET to build a winforms database interface and work-automation app. I am
project: Using VB.NET to build a winforms database interface and work-automation app. I am
Project : Game in Flex builder 4 (Actionscript Project) Language : Actionscript 3 This
Project name : pro Project location : /home/cha0s/pro/ Applications location : /home/cha0s/pro/apps/ , where
Our project uses XJC to generate Java classes from an XSD. I'm using JAVA
Project#1 has some interfaces and classes that project#2 references. Now I want to use
My project compiles, link and run in xp32 then I tried to cross compile

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.