2

I am creating a Java REST web service. For some reason the startup page index.jsp is giving me a HTTP Status 404 - Not Found error. My index.jsp is in the web folder. My web.xml contains

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

It also contains

<servlet-mapping>
    <servlet-name>Jersey</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

I noticed that when I remove the servlet mapping the index page works. But I need that mapping. I have been reading similar posts but couldn't find an answer to my question. Would appreciate any help. Thank you.

Ashish Bahl
  • 1,482
  • 1
  • 18
  • 27
Harlan Gray
  • 341
  • 6
  • 20

2 Answers2

2

Make your web.xml file like this

this thing as it is :

 <?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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

than this line contains youe project name

<display-name>Project name</display-name>

this is your welcome file list

 <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>

Servlet Mapping

   <servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>

Here you need to remove * in your servlet mapping change your mapping code

    <servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/Jersey</url-pattern>

  • 1
    Your answer didn't work but it helped me. I added /Jersey/*. So I had to add a * but with another part into the url. Then my index page works and also the web service (but with an extra part in the url) I can live with that but not sure if that part can be eliminated. Thanks again. – Harlan Gray Nov 28 '16 at 05:58
1

The initial page should always be index.html not index.jsp. Also,replace the references you have to index.jsp with index.html. It wil work. On loading the index.html page you can redirect it to any page you like. The Glassfish or Tomcat Server always looks for it and loads it first.

Nik
  • 452
  • 5
  • 17
  • I tried this too but doesn't work. It works only when the servlet mapping is removed. It could be something really small as I am not a java guru. – Harlan Gray Nov 28 '16 at 05:43