Java servlet throws an exception when responding to a request with a file












0















I'm pretty new to Java server applications. I'm trying to create a simple servlet returning an HTML file. I've tried with printing output from the servlet (the commented out part of the code below), which worked fine, but the file approach crashes immediately.
Below the code I've posted the exceptions I receive, however those aren't very descriptive neither to me nor Google.
Maybe it's some jar file I'm missing at some deployment stage?



@SOLVED: A couple of hours and pushup sets later I've found out '/' is not an acceptable suburl, changing to '/login' solved it.



File sctructure:



cache
-src
--cache
---LoginServlet.java
-WebContent
--META-INF //autogenerated
--WEB-INF
---web.xml
--index.html


LoginServlet.java



package cache;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
/*PrintWriter out = response.getWriter();
out.print("asd");*/
request.getRequestDispatcher("index.html").forward(request, response);
}
}


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" id="WebApp_ID" version="3.0">
<display-name>cache</display-name>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>cache.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


browser exception (repeated, I'm pasting only a single repetition)




javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
cache.LoginServlet.doGet(LoginServlet.java:16)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




eclipse exception (repeated plenty of times)




Jan 19, 2019 2:40:28 PM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [Login] in context with
path [/cache] threw exception [Servlet execution threw an exception]
with root cause java.lang.StackOverflowError at




this line is repeated a lot




javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:408)
at




single unwrap




org.apache.catalina.core.ApplicationDispatcher.unwrapRequest(ApplicationDispatcher.java:797)
at




and this repeated until the end




org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at cache.LoginServlet.doGet(LoginServlet.java:16) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




@EDIT I've added a piece of stack trace I initially ignored as I hadn't seen the starting part of it, and I thought it was something concurrent.










share|improve this question

























  • There isn't a chain of "Caused by:" bits?

    – Joe C
    Jan 19 at 13:58











  • I've updated to exception stack trace. I didn't notice the beginning was printed, I thought it got overridden by the output.

    – Yyyeey
    Jan 19 at 14:15
















0















I'm pretty new to Java server applications. I'm trying to create a simple servlet returning an HTML file. I've tried with printing output from the servlet (the commented out part of the code below), which worked fine, but the file approach crashes immediately.
Below the code I've posted the exceptions I receive, however those aren't very descriptive neither to me nor Google.
Maybe it's some jar file I'm missing at some deployment stage?



@SOLVED: A couple of hours and pushup sets later I've found out '/' is not an acceptable suburl, changing to '/login' solved it.



File sctructure:



cache
-src
--cache
---LoginServlet.java
-WebContent
--META-INF //autogenerated
--WEB-INF
---web.xml
--index.html


LoginServlet.java



package cache;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
/*PrintWriter out = response.getWriter();
out.print("asd");*/
request.getRequestDispatcher("index.html").forward(request, response);
}
}


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" id="WebApp_ID" version="3.0">
<display-name>cache</display-name>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>cache.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


browser exception (repeated, I'm pasting only a single repetition)




javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
cache.LoginServlet.doGet(LoginServlet.java:16)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




eclipse exception (repeated plenty of times)




Jan 19, 2019 2:40:28 PM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [Login] in context with
path [/cache] threw exception [Servlet execution threw an exception]
with root cause java.lang.StackOverflowError at




this line is repeated a lot




javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:408)
at




single unwrap




org.apache.catalina.core.ApplicationDispatcher.unwrapRequest(ApplicationDispatcher.java:797)
at




and this repeated until the end




org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at cache.LoginServlet.doGet(LoginServlet.java:16) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




@EDIT I've added a piece of stack trace I initially ignored as I hadn't seen the starting part of it, and I thought it was something concurrent.










share|improve this question

























  • There isn't a chain of "Caused by:" bits?

    – Joe C
    Jan 19 at 13:58











  • I've updated to exception stack trace. I didn't notice the beginning was printed, I thought it got overridden by the output.

    – Yyyeey
    Jan 19 at 14:15














0












0








0


0






I'm pretty new to Java server applications. I'm trying to create a simple servlet returning an HTML file. I've tried with printing output from the servlet (the commented out part of the code below), which worked fine, but the file approach crashes immediately.
Below the code I've posted the exceptions I receive, however those aren't very descriptive neither to me nor Google.
Maybe it's some jar file I'm missing at some deployment stage?



@SOLVED: A couple of hours and pushup sets later I've found out '/' is not an acceptable suburl, changing to '/login' solved it.



File sctructure:



cache
-src
--cache
---LoginServlet.java
-WebContent
--META-INF //autogenerated
--WEB-INF
---web.xml
--index.html


LoginServlet.java



package cache;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
/*PrintWriter out = response.getWriter();
out.print("asd");*/
request.getRequestDispatcher("index.html").forward(request, response);
}
}


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" id="WebApp_ID" version="3.0">
<display-name>cache</display-name>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>cache.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


browser exception (repeated, I'm pasting only a single repetition)




javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
cache.LoginServlet.doGet(LoginServlet.java:16)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




eclipse exception (repeated plenty of times)




Jan 19, 2019 2:40:28 PM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [Login] in context with
path [/cache] threw exception [Servlet execution threw an exception]
with root cause java.lang.StackOverflowError at




this line is repeated a lot




javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:408)
at




single unwrap




org.apache.catalina.core.ApplicationDispatcher.unwrapRequest(ApplicationDispatcher.java:797)
at




and this repeated until the end




org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at cache.LoginServlet.doGet(LoginServlet.java:16) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




@EDIT I've added a piece of stack trace I initially ignored as I hadn't seen the starting part of it, and I thought it was something concurrent.










share|improve this question
















I'm pretty new to Java server applications. I'm trying to create a simple servlet returning an HTML file. I've tried with printing output from the servlet (the commented out part of the code below), which worked fine, but the file approach crashes immediately.
Below the code I've posted the exceptions I receive, however those aren't very descriptive neither to me nor Google.
Maybe it's some jar file I'm missing at some deployment stage?



@SOLVED: A couple of hours and pushup sets later I've found out '/' is not an acceptable suburl, changing to '/login' solved it.



File sctructure:



cache
-src
--cache
---LoginServlet.java
-WebContent
--META-INF //autogenerated
--WEB-INF
---web.xml
--index.html


LoginServlet.java



package cache;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
/*PrintWriter out = response.getWriter();
out.print("asd");*/
request.getRequestDispatcher("index.html").forward(request, response);
}
}


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" id="WebApp_ID" version="3.0">
<display-name>cache</display-name>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>cache.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


browser exception (repeated, I'm pasting only a single repetition)




javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
cache.LoginServlet.doGet(LoginServlet.java:16)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




eclipse exception (repeated plenty of times)




Jan 19, 2019 2:40:28 PM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [Login] in context with
path [/cache] threw exception [Servlet execution threw an exception]
with root cause java.lang.StackOverflowError at




this line is repeated a lot




javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:408)
at




single unwrap




org.apache.catalina.core.ApplicationDispatcher.unwrapRequest(ApplicationDispatcher.java:797)
at




and this repeated until the end




org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at cache.LoginServlet.doGet(LoginServlet.java:16) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)




@EDIT I've added a piece of stack trace I initially ignored as I hadn't seen the starting part of it, and I thought it was something concurrent.







java html exception servlets






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 16:54







Yyyeey

















asked Jan 19 at 13:55









YyyeeyYyyeey

33




33













  • There isn't a chain of "Caused by:" bits?

    – Joe C
    Jan 19 at 13:58











  • I've updated to exception stack trace. I didn't notice the beginning was printed, I thought it got overridden by the output.

    – Yyyeey
    Jan 19 at 14:15



















  • There isn't a chain of "Caused by:" bits?

    – Joe C
    Jan 19 at 13:58











  • I've updated to exception stack trace. I didn't notice the beginning was printed, I thought it got overridden by the output.

    – Yyyeey
    Jan 19 at 14:15

















There isn't a chain of "Caused by:" bits?

– Joe C
Jan 19 at 13:58





There isn't a chain of "Caused by:" bits?

– Joe C
Jan 19 at 13:58













I've updated to exception stack trace. I didn't notice the beginning was printed, I thought it got overridden by the output.

– Yyyeey
Jan 19 at 14:15





I've updated to exception stack trace. I didn't notice the beginning was printed, I thought it got overridden by the output.

– Yyyeey
Jan 19 at 14:15












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267814%2fjava-servlet-throws-an-exception-when-responding-to-a-request-with-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267814%2fjava-servlet-throws-an-exception-when-responding-to-a-request-with-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage