• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Web.xml file is not created at the time of creating a new jsp in netbeans

 
Greenhorn
Posts: 15
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Experts!!!

I am new to jsp & Servlets and need help to understand below below behavior.

IDE used : NetBeans 8.0.2

When I was creating a new servlet in netbeans, I was getting a web.xml file in WEB-INF folder with servlet mapping and other details, on running that web project it works fine.

However when I create a new jsp file in a separate project just to print Hello Word, it does not create a web.xml file but still works fine. I am a bit confused why web.xml file is not created or what is the reason jsp ran without web.xml?.

Please help.!!!
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using the "@WebServlet" annotation, the web.xml is not required. But NetBeans usually creates a default web.xml when you create a new web project. Are you using "Java Web"/"Web Application" when you create the new project?
 
sourabh kanoongo
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Kevin..!!!

Yes I am creating a "Java Web"\"Web Applicadstion". I am not using @WebServlet annotations(what does they do I am not sure..).. jsp file is placed in Web Pages directory.

Below is my JSP file code:-


<%--
Document : testjsp
Created on : Mar 11, 2015, 7:13:48 PM
Author : skanoongo
--%>



code for index.html from where I am triggering the JSP:-




Please help.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sourabh kanoongo wrote:
However when I create a new jsp file in a separate project just to print Hello Word, it does not create a web.xml file but still works fine.


I didn't catch this the last time. A jsp file does not need an entry in web.xml. Even though a jsp gets compiled into a servlet, the container takes care of all that. You don't do a mapping for a jsp like you would for a servlet.

However, I'm still puzzled as to why your project did not create a web.xml. When I create a new project in Netbeans 8.0.2 It creates a "Web Pages" folder, and under that is WEB-INF and in that is a web.xml with the default contents like so:


You must have a WEB-INF folder for the container to know it's a web application. Is that present? Is it empty?
 
sourabh kanoongo
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Kevin..

Yes whenever I create a web project, WEB-INF folder is created by default. while creating a new web project :-
case 1. if I select "Enable contexts and Dependency Injection" checked, WEB-INF folder contains beans.xml having below code :-



case 2 : if I do not check option "Enable contexts and Dependency Injection" then WEB-INF folder is empty.

But in both above cases, there is no Web.xml file created by default.

Please advise.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sourabh kanoongo wrote:
case 1. if I select "Enable contexts and Dependency Injection" checked, WEB-INF folder contains beans.xml having below code :-


Now you lost me. I get no such option when I create a new project. It sounds like you are using Spring or some other framework that I'm not familiar with. That is probably related to the web.xml issue, but I can't address that. What framework are you using and I'll move this to a forum where you have a better chance of getting some help.
 
sourabh kanoongo
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Kevin!! Thanks for your reply.

I am not using any Framework, just creating a simple Web project. I have got the answer by some more research, and below is the observation.

1. When I create a new project on step 3 (Server and Settings) I get the option of selecting Java EE Version in drop down list. if I select the Java EE Web 6, check box of "Enable contexts and Dependency Injection" gets visible and can check it or un check it. No Web.xml file created by default if a new web project is created like this.

2. When I create a new project on step 3 and select Java EE 5, "Enable contexts and Dependency Injection" check box gets disappears. Default Web.xml file is created now in WEB-INF folder.

So the conclusion is having a default web.xml file depends upon the Java EE Version you select, it is not by default created for Version 6.

 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I'm on Tomcat 6 so using EE 6 is not an option for me. Netbeans is assuming that if you are on EE 6 (Tomcat 7 or Glassfish) then you are going to use annotations and don't need the web.xml. Interesting.

Thanks for coming back with the solution. I learned something today and I'm sure it will help someone else in the future. Have a cow!
 
sourabh kanoongo
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kevin..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic