Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web.config file like

 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just starting to build a web application using java, and as I do not have much experience while working with JSP or servlets, I wonder if I can have a Web.config file like when working with asp.net, where I can put all the configurations for my application. I don't think Java has this kind of thing, but I think the same result can be archieve if using JAXP. Is it what you guys normally do, for your xml configuration files.


Thanks in advance,

MeTitus
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64854
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Me_Titus",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about it.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to J2EE World!

Yes, For building web application using JSP/Servlet, there is something called web.xml(also called as Deployment Descriptor). Using this you can do lot of stuffs. Some are like mapping different URL to different servlet, adding welcome file for application etc.,

Try deploying an sample application in Tomcat webserver.
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prabhu thanks for the reply.


I am using Netbeans to develop my web site and there is a nice gui which helps a lot on entering data into the web.xml file.

My question is:

How do I access that information from a java class?

Thanks,

Marco
[ November 20, 2006: Message edited by: Marco Alexandre ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64854
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of information are you trying to access?

Generally, there are two types of info entered into the deployment descriptor available to the code:

- Context parameters: name/value pairs available anywhere in the web app

- Servlet init parameters: name/value pairs associated with a specific servlet
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I am not really getting what the web.xml is?? Is it just a deployment description file that "says" how a set of files should be deployed?? I dont have that kind of knowledge because I have never worked with servlets, but I tought that this file was the same as the web.config file in .net, apparently it is, but in the web.config file I could set for eg the connection string for a database, and use that info in any C# class.


That is what I am looking for. I could implement that using JAXB, but if there iis that already then I should concentrate my efforts in other functionalities.

Thanks Bear Bibeault,

Marco
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could it be this???

Context parameters: name/value pairs available anywhere in the web app

I think this would do it.
But how can I access that info from any class?

Thanks,

Marco
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64854
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Study the ServletContext API.
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Study the ServletContext API.


I would if I had time...

But I will look at it and see if it possible to get what I want by using it.

Thanks,

Marco
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is sort of what I was looking for.

<context-param>
<param-name>Developer</param-name>
<param-value>Crazy@weird.com</param-value>
</context-param>

String s =
getServletContext.getInitParameter("Developer");


http://www.sap-img.com/java/difference-between-servletcontext-and-servletconfig.htm


Thanks anyway,

Marco
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some example apps that show how to use both servlet and context init params on http://simple.souther.us
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic