Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Web.config file like

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about it.
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Study the ServletContext API.
 
Marco Alexandre
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic