• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access Context Parameters from normal java file  RSS feed

 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

I have written a JSP to get data from the DATABASE and display the results.

For that I configured web.xml to get the IP address,port,username,password etc... as context parameters.

Now My PROBLEM is - I have to move the Java code in JSP to separate Java file. How can I use the context parameters in that Java file.
Is it possible? Or writing servlet is the only means?

Thank You
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh Sunkara wrote:Is it possible? Or writing servlet is the only means?

Yes. introducing a servlet is a good choice . pass the servletcontext to a java class method as a argument from jsp[calling a method from jsp is poor practice]
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You SeethRaman

DO you mean to say its possible to access the context parameters if we pass ServletContext as argument to my function?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:pass the servletcontext to a java class method as a argument

I would recommend against this. Do not pass servlet and JSP classes to non-servlet and JSP classes. It creates needless tight coupling and limits reuse.

Rather, either pass the values that you need as parameters, or create a class that holds them and pass that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!