0

Home.java file

RequestDispatcher view = request.getRequestDispatcher("/WEB-
    INF/views/Login.html");
view.include(request, response);

web.xml file

This works --

<servlet>
  <servlet-name>Home</servlet-name>
  <servlet-class>home.Home</servlet-class>
 </servlet>

 <servlet-mapping>
  <servlet-name>Home</servlet-name>
  <url-pattern>/home</url-pattern>
 </servlet-mapping>

This doesn't work --

<servlet>
  <servlet-name>Home</servlet-name>
  <servlet-class>home.Home</servlet-class>
 </servlet>

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

In the second case there is repititive error printing in the console.

SEVERE: Servlet.service() for servlet [Home] threw exception
java.lang.StackOverflowError
    at javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:409)
    at javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:409)
    at javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:409)

I have found questions on stackoverflow about the same error but I cant understand any of them

java.lang.StackOverflowError being thrown by class that doesn't exist

Faces Servlet threw exception java.lang.StackOverflowError

Mickael
  • 3,506
  • 1
  • 21
  • 33
Maroof
  • 139
  • 1
  • 12
  • 2
    `/` means: **all** requests, to **any** path, are handled by this servlet. So you're forwarding to the same servlet, which is forwarding to the same servlet, etc. etc., hence the StackOverflowError – JB Nizet Sep 05 '17 at 16:10
  • So what should I do to render an HTML page when the user lands at '/' the root. – Maroof Sep 05 '17 at 16:13
  • 1
    Google is your friend: https://stackoverflow.com/questions/1030302/how-can-i-map-a-root-servlet-so-that-other-scripts-are-still-runnable – JB Nizet Sep 05 '17 at 16:16
  • Thanks @JBNizet . The problem is resolved. – Maroof Sep 05 '17 at 16:20

0 Answers0