0

I have a little problem. Is it possible 'delete' index.html and create (to replace index.html) index.jsp? How?

I don't find any files (web.xml, glassfish-resource.xml) with the address to the home page (index.html) to change it (for index.jsp). I have not found an answer on the Internet...

Thanks for replies!

Marco_Díaz
  • 3
  • 1
  • 1
  • 2

2 Answers2

6

What you need is to configure the welcome-file-list for your application. By default, it's index.html, which is why you don't find anything defining it.

Take a look at web.xml Deployment Descriptor Elements You basically need

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Adrian Pang
  • 1,125
  • 6
  • 12
  • Thank you all! Adrian's answer worked for me. The mini-example was very useful: http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/components.html#109211 Just today I started with this. Time to read the Oracle documentation. Thank you again! – Marco_Díaz May 16 '14 at 23:10
  • isn't web.xml outmoded? annotations are preferred, I believe. – Thufir Jan 22 '15 at 11:24
  • It is definitely more convenient to use annotations in many cases, but AFAIK there's no way you can customize the welcome file list using annotations. Think about it this way: while it makes sense to define annotation in the servlet class to describe metadata that used to live in the web.xml, there's no class you can add annotations for in order to describe global information such as the welcome file list. – Adrian Pang Jan 23 '15 at 18:25
1

If you delete index.html then index.jsp will automatically take over for requests to http://yourserver/yourapp/.

Do you have the problem of users having bookmarked http://yourserver/yourapp/index.html itself so you need backwards compatibility? You can map index.jsp to respond to requests for index.html in web.xml:

  <servlet>
    <servlet-name>indexhtml</servlet-name> 
    <jsp-file>/index.jsp</jsp-file>
  </servlet>
  <servlet-mapping>
    <servlet-name>indexhtml</servlet-name>
    <url-pattern>/index.html</url-pattern>
</servlet-mapping> 

You could also use *.html there to have index.jsp respond to all requests for any .html:

<url-pattern>*.html</url-pattern>
developerwjk
  • 8,619
  • 2
  • 17
  • 33