11

I create a simple web application in NetBeans, named WebApplication1. There is a file created, named index.jsp. When I run the application, and the browser goes to index.jsp.

Nowhere in the project is it mentioned as the welcome page. Then how is it going there?

I checked files build.xml, glassfish-web.xml, all XML files, and prop files in the nbproject folder, but nowhere is the mention of index.jsp. How is it taking?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1559227
  • 1,021
  • 2
  • 10
  • 13

4 Answers4

19

In NetBeans by default, if you create a project with no added frameworks, no deployment descriptor (file web.xml) is provided.

To change it, right click on the project and select New>Other>web>Standard Deployment Descriptor(web.xml).

Now edit the web.xml file and set

<welcome-file-list>
    <welcome-file>newjsp.jsp</welcome-file>
</welcome-file-list>

in order to change the default to file newjsp.jsp.

Explicitly for Tomcat...

If no web.xml file is provided in the application, the default web.xml($CATALINA_HOME/conf/web.xml) of Tomcat is supplied to the application. This deployment descriptor has the following lines:

<!-- -->
<!-- If you define welcome files in your own application's web.xml -->
<!-- deployment descriptor, that list *replaces* the list configured -->
<!-- here, so be sure to include any of the default values that you wish -->
<!-- to use within your application. -->

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

That is why the index.jsp file is shown by default.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
6

If you are using NetBeans you need to click right the button on your project and then properties. A new pop up window will open, and on the left menu there will be a label called Run. Click there and then in the "relative URL". You should input:

./nameOfYourJspFile.jsp

And that's all!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SomeAnonymousPerson
  • 3,173
  • 1
  • 21
  • 22
  • 1
    This is great can you briefly tell me what that means ? And why I couldn't get the page to load by just using a – MadMax Sep 13 '18 at 01:32
1

Make sure the JSP code file is not in the Web-Inf directory. It should be in the Web Pages directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sar
  • 11
  • 1
0

It could be index.html or index.jsp, the welcome page of your web application in NetBeans.

Also there is also a bug in NetBeans IDE 8.2: even if you make changes in the descriptor web.xml file (by adding the "welcome-file-list" tag), "Run" runs the old version of your index!

To fix this, put './index.html' in the 'Relative URL' field in the category "Run" in properties of your project.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JGaber
  • 37
  • 3