0

Hello am trying to change the default start page for my dynamic project in eclipse from index.jsp to welcome.jsp. I have gone through some of the answers on web and I changed the welcome-file-list accordingly but still its not working.

my web.xml is like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Decryption</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    **<welcome-file>welcome.jsp</welcome-file>**
  </welcome-file-list>
</web-app>

I have edited the welcome file list and i have added <welcome-file>welcome.jsp</welcome-file> to it. But still its not working. Any help will be appreciated.

user3222718
  • 242
  • 1
  • 7
  • 27

2 Answers2

0

The order in which you list your <welcome-file-list> entries is important because the web container looks at this list from top to bottom and stops searching at the first match.

So, in case your web content directory has another file, like index.jsp, that is listed before, welcome.jsp will not be served. So, just moving the entry to the top should solve your problem.

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

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

By the way, you could also choose to drop all other entries and just keep the one that points to your index file. Listing all the entries is not mandatory.

Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
  • No this didnt work for me. the same thing is happening it is displaying directory listing. – user3222718 Jan 19 '15 at 08:29
  • What is the exact URL you are using in the browser? – Ravi K Thapliyal Jan 19 '15 at 08:32
  • http://localhost:8080/Decryption/ .. Decryption is the project name. and am just running the thing on eclipse the default browser is accessing this url – user3222718 Jan 19 '15 at 08:32
  • and you're getting a directory listing for `/` i.e. are you seeing `/welcome.jsp` as one of the files? – Ravi K Thapliyal Jan 19 '15 at 08:33
  • Can you verify if the `web.xml` at `tomcat_install_dir/webapps/Decryption/WEB-INF/web.xml` has the changes you're making? – Ravi K Thapliyal Jan 19 '15 at 08:38
  • Can you make `welcome.jsp` the only entry in that `web.xml` manually, and open your site in the browser again just to confirm if this is the issue? – Ravi K Thapliyal Jan 19 '15 at 08:49
  • i tried but the same issue... its showing the directory listing which includes welcome.jsp – user3222718 Jan 19 '15 at 08:52
  • This is definitely some environment issue. Your project isn't setup correctly. I think your Eclipse isn't deploying its changes into Tomcat. (1) Rename your welcome.jsp to welcome.bak from Eclipse. Check if the directory listing reflects the change. (2) If not, check the file path of welcome.bak by right-clicking > properties from the project explorer. – Ravi K Thapliyal Jan 19 '15 at 08:59
  • i want one confirmation first.. in webcontent i have both index.jsp and welcome.jsp. should i delete index.jsp? – user3222718 Jan 19 '15 at 09:03
  • Just rename it to .bak so that it doesn't interfere. The directory listing should also reflect this change. – Ravi K Thapliyal Jan 19 '15 at 09:05
  • again directory listing and this time even index.bak is coming in directory listing – user3222718 Jan 19 '15 at 09:08
  • Let index.bak be as it is. Change welcome.bak to welcome.jsp. Configure web.xml with welcome.jsp the only welcome-file. Change welcome.jsp's content to force a container compile. Now check in the browser. If this doesn't solve the problem, please provide screenshots with as much details on directory structure and physical locations as possible. – Ravi K Thapliyal Jan 19 '15 at 09:15
  • if i have both index.jsp and welcome.jsp in web content and web.xml then the browser is accessing http://localhost:8080/Decryption/ but displaying nothing on the screen – user3222718 Jan 19 '15 at 09:34
  • Are you printing any output in your index and welcome jsps? Can you post the two files? Also check tomcat logs for any errors while rendering these files. At this point I would suggest you to create a new dynamic web project from scratch and check if this problem persists. – Ravi K Thapliyal Jan 20 '15 at 01:26
0

As Said by Ravi order of files matter in web.xml So in case you want welcome.jsp to be shown then keept this entry as first line in <welcome-file-list> tag.

Also its not mandatory to have all files like index.html,index.htm,index.jsp .... etc under <welcome-file-list> tag . If you know your home page then you can add only one jsp as below.

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

Note: Also as an advice you should put your jsp's under web-inf folder . refer URL for details

Community
  • 1
  • 1
Shirishkumar Bari
  • 2,692
  • 1
  • 28
  • 36