Change index.html for index.jsp (JavaEE+Glassfish)

你。 提交于 2019-12-25 02:44:25

问题


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!


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/23705519/change-index-html-for-index-jsp-javaeeglassfish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!