비슷한 질문을 많이 읽고 문제를 해결하기 위해 제안 된 모든 방법을 시도했지만 성공하지 못했습니다. (: 8080/testWebApp/홈 로컬 호스트) : RequestDispatcher를 가져올 수 없습니다.
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)
내가 받는다는 3.3.9 및 7.0.70-1 tomcat7를 사용하는 지금은 정말이 함께 할 수있는 어떤 아이디어가 없습니다. web.xml의 코드 여기
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);
}
}
됩니다 :
<?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 코드 :
을 여기webApp/
pom.xml
src/
main/
java/
test/web/servlet/
TestServlet.java
webapp/
index.html
WEB-INF/
views/
home.jsp
web.xml
가 TestServlet 코드 : 내 프로젝트 디렉토리는 다음과 같은 계층 구조를 가지고
<%@ 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>
일부 유용한 줄은 pom.xm l :
<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>
감사합니다.
을 파견되어,이 [duplicate] (/ questions/218384/what-is-a-nullpoint 예고 - 어떻게 -해야합니까 - 고침 - 그것)입니다. 당신이 물어야하는 것은'RequestDispatcher'가 왜 null인지입니다. – EJP
수정 해 주셔서 감사합니다! – user3856196