2

I am going through one web development process in which, I have two parameters say username and password as context parameters in web.xml file like:-

<context-param>
    <param-name>uname</param-name>
    <param-value>demouser</param-value>
    </context-param>
    <context-param>
    <param-name>pwd</param-name>
    <param-value>demopwd</param-value>
    </context-param>

One of my servlet is getting the uname and pwd field by getServletContext.getgetInitParameter("uname"); and simillarly the pwd field,

Now at some point of time, I want to change the values of context parameters through same servlet or other. How to do that. Please help me out by few suggestions.

Thanks & Regards, Ars.

6
  • Change it permanently or temporarily? Commented Mar 19, 2012 at 9:16
  • @EJP, i want to change it permanently and one more thing, for my JSP how can I exceute the whole Servlet by only loading the JSP? Commented Mar 19, 2012 at 9:31
  • 1
    Questions should be in the question. I don't understand that one. Commented Mar 19, 2012 at 9:32
  • suppose we have one abc.jsp with servlet abcServ as a controller, then if once the JSP is loaded in the browser, can we execute all the life cycle methods of the abcServ(controller) with performing any action in abc.jsp(like submitting the form, clicking the hyperlinks) ? Commented Mar 19, 2012 at 9:39
  • 1
    As I have already said, questions should be in the question. Not in the comments to the question. This one sounds like a new question, so post it accordingly. I cannot help you further. Commented Mar 19, 2012 at 9:48

1 Answer 1

2

You cant modify context parameters directly, but you could use ServletContextListener implementation to keep and modify all the necessary variables and objects. See http://docs.oracle.com/javaee/5/tutorial/doc/bnafi.html for details.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Osw, Can i make servlet to implement ServletContextListener and can we use <!-- <listener> <listener-class> src.RecieverModule </listener-class> </listener>--> in our web.xml file to make this a listener?
@Ars Why? Keep the functions separate. There seems to be some risk of your servlet being instantiated twice the way you suggest.
@Ars, no it's a separate class which should be registered in web.xml (just like you mentioned) or via @WebListener annotation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.