-1

In Spring mvc how we can set a default jsp page i.e., as soon as we run the project on server a default jsp page should show up in the browser, just like in jsf we can achieve it using below code in web.xml :

 <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
Santhosh
  • 8,181
  • 4
  • 29
  • 56
Sharique
  • 781
  • 5
  • 12
  • 33

3 Answers3

0

It is same in spring also ,

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

you can set in the web.xml.but you should have abc.jsp outside the web-inf to make it visible to the browser.

see also :

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • Its giving 404 error, with a description "The requested resource is not available." I have put all my jsps under pages folder inside WEB_INF, but index.jsp is inside WEB-INF only – Sharique Feb 02 '15 at 12:26
  • NO . you cant access the `index` file directly from the `web-inf` . put it inside the `web pages` to display it as welcome page. other pages you can have it inside the `web-inf` as it will be intercepted with dispatcher-servlet – Santhosh Feb 02 '15 at 12:28
  • you mean to say that my default welcome file should be inside web content and the rest I can put it inside WEB_INF and the path of these I can get it from controller, right??? – Sharique Feb 02 '15 at 12:29
0

While using spring also u can mention the same in web.xml

   <welcome-file-list>
         <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
Dipen Adroja
  • 415
  • 5
  • 15
0

How about adding default controller pointing to index.jsp?

@RequestMapping(value = "/", method = GET)
public String index() {
   return "index";
}

p.s. Did you specified a view resolver?

Yegor Chumakov
  • 450
  • 4
  • 11
  • /WEB-INF/Pages/ .jsp This is what I wrote in my dispatcher-servlet.xml and the same code I tried which you are suggesting but I don't know why it's not working – Sharique Feb 02 '15 at 12:35
  • This will work in case your index.jsp is located in /WEB-INF/Pages directory as view-resolver will lookup pages placed in aforementioned folder. – Yegor Chumakov Feb 02 '15 at 12:39
  • Maybe welcome-file -list tag was also there in web.xml so it was conflicting..and as soon as I removed it, this one is working too. Thanks :) – Sharique Feb 02 '15 at 12:42