aspose file tools*
The moose likes Servlets and the fly likes Web.config file like Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Web.config file like" Watch "Web.config file like" New topic
Author

Web.config file like

Marco Alexandre
Greenhorn

Joined: Feb 11, 2006
Posts: 9
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marco Alexandre
Greenhorn

Joined: Feb 11, 2006
Posts: 9
Sorry about it.
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

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.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Marco Alexandre
Greenhorn

Joined: Feb 11, 2006
Posts: 9
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

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

Joined: Feb 11, 2006
Posts: 9
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

Joined: Feb 11, 2006
Posts: 9
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

Study the ServletContext API.
Marco Alexandre
Greenhorn

Joined: Feb 11, 2006
Posts: 9
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

Joined: Feb 11, 2006
Posts: 9
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

Joined: Dec 11, 2004
Posts: 13410

I have some example apps that show how to use both servlet and context init params on http://simple.souther.us


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: Web.config file like