I've read lots of similar questions and tryed all suggested methods for fixing the problem, however it's unsuccessfully. Now I really don't have any ideas what to do with this (localhost:8080/testWebApp/home):
HTTP Status 500 -
...
exception
java.lang.NullPointerException
test.web.servlet.TestServlet.doGet(TestServlet.java:37)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
I use maven 3.3.9 and tomcat7 7.0.70-1. My project directory has the following hierarchy:
webApp/
pom.xml
src/
main/
java/
test/web/servlet/
TestServlet.java
webapp/
index.html
WEB-INF/
views/
home.jsp
web.xml
Here is the TestServlet code:
package test.web.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
@WebServlet(urlPatterns = { "/home"})
public class TestServlet extends HttpServlet {
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public TestServlet() {
super();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/views/home.jsp");
//The following attempts are unsuccessful too:
//RequestDispatcher dispatcher = request.getRequestDispatcher("/home.jsp");
//RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/views/home.jsp");
dispatcher.forward(request, response); // error (37 line)
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
Here is web.xml code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_4.dtd">
<web-app>
<welcome-file-list>
<welcome-file>home</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
home.jsp code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home Page</title>
</head>
<body>
<%-- <jsp:include page="main.jsp"></jsp:include> --%>
<h3>Home</h3>
<br><br>
<b>You have the following options:</b>
<ul>
<li>Login</li>
</ul>
</body>
</html>
Some useful lines from pom.xml:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>tomcat-7.0.70-1</server>
<url>http://localhost:8080/manager/text</url>
<path>/testWebApp</path>
</configuration>
</plugin>
Thank you for help!