Not Showing Welcome Page JSP

droidev picture droidev · Apr 30, 2015 · Viewed 7.2k times · Source

I have created dynamic web project in eclipse and added index.jsp file, obviously thats my welcome page.I have added it in web.xml,I am using angular js for front-end interface management.

here is my web.xml

<?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" metadata-complete="false" version="3.0">
<welcome-file-list>

    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
    <servlet>
    <description></description>
    <display-name>ValidateLogin</display-name>
    <servlet-name>ValidateLogin</servlet-name>
    <servlet-class>ValidateLogin</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ValidateLogin</servlet-name>
    <url-pattern>/ValidateLogin</url-pattern>
  </servlet-mapping>

</web-app>

now what my issue is When I run the project it is showing loading and not opening any content. but if I added the project url+index.jsp in browser address bar then the page loads successfully. I am using route provider in angular js script and that is as follows

app.js

var myApp = angular.module('myApp', [
    'ngRoute',
    'appController'
    ]);

myApp.config(['$routeProvider',function ($routeProvider) {

    $routeProvider.
    when('/home', {
        templateUrl: 'views/login.jsp',
        controller: 'LoginController'
    }).
    when('/main', {
        templateUrl: 'views/Home.jsp',
        controller: 'MainController'
    }).
    otherwise({ redirectTo: '/home' });

}]);

here is my dir structure

enter image description here

what is the issue ? can anyone answer ?

Answer

underdog picture underdog · Apr 30, 2015
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Add.jsp extension in index

Make sure your index.jsp is outside WEB-INF folder

For accessing the jsp the correct url will

http://localhost:8080/ProjectName/index.jsp

Change the port no as per your server. You need to provide the project url for accessing the jsp. Say you have 4 projects deployed on your server each having index.jsp. How will the container figure out which index.jsp to run if you don't provide the project url.