This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes Can we make a web application without using web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can we make a web application without using web.xml" Watch "Can we make a web application without using web.xml" New topic
Author

Can we make a web application without using web.xml

rahul S Sharma
Greenhorn

Joined: Jun 08, 2011
Posts: 21
Hi Folks,
In a project suppose we have only jsp pages not even a single servlet . Do we still need to add web.xml in our project..?
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2053
No. The java servlet specification requires it.

Jsp IS a servlet. At the time the jsp involved is requested, it is first converted into a servlet, compiled, and then executed, to return the reply.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

rahul S Sharma wrote:In a project suppose we have only jsp pages not even a single servlet .

That would be a project following very poor practices. Why would even contemplate such a thing?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
In Servlet 3.0, you can also use annotations instead of web.xml.
here you can read about them..
Here
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2053
Punit Jain wrote:In Servlet 3.0, you can also use annotations instead of web.xml.
here you can read about them..
Here


My post above is wrong, as pointed out by Punit.

You can have a war file without a web.xml, if you are using jsps only.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
as far as i know after scanning the class, it servlet container found annotation it will generate web.xml by it's own.
and also servlet 3.0 support these annotataions only,
@WebServlet
@WebServletContextListener
@ServletFilter
@InitParam

if you want to do something more with web.xml, (ie. security roles etc).
you have to do it explicitly in web.xml.

please correct me if i am wrong.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

I'm far less concerned with whether there's a web.xml or not than with the presences of only JSPs. That means that everything, views, model, and controllers, are implemented using JSPs and that would be a very very bad thing!
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
just tested in tomcat 6, jsp runs without web.xml..
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2
just test annotations in servlet 3.0 and tomcat 7,
servlet runs successfully, but no web.xml is created.
annotation i used:

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2053
I checked the 3.0 specs for servlet, and I cant find any statement saying that the container is required to generate a web.xml. If there is no such requirement, it is up to each container implementation if it will generate a web.xml or not.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2

I checked the 3.0 specs for servlet, and I cant find any statement saying that the container is required to generate a web.xml. If there is no such requirement, it is up to each container implementation if it will generate a web.xml or not.

perhaps...
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10069
    
163

Jesus Angeles wrote:I checked the 3.0 specs for servlet, and I cant find any statement saying that the container is required to generate a web.xml. If there is no such requirement, it is up to each container implementation if it will generate a web.xml or not.


It's not the server which generates the web.xml. The application developer is expected to create the web.xml. Starting Servlet 3.0, the web.xml is optional which means that the application developer need not create it, if he doesn't require it.


[My Blog] [JavaRanch Journal]
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 998
    
    2

It's not the server which generates the web.xml. The application developer is expected to create the web.xml. Starting Servlet 3.0, the web.xml is optional which means that the application developer need not create it, if he doesn't require it.


okay..
thanks for clarification Jaikiran Pai..
 
Don't get me started about those stupid light bulbs.
 
subject: Can we make a web application without using web.xml