Jsp resolve the situation on under WEB-INF not run

Tell us about the role of the WEB-INF

 

1.Jsp page can be placed in WEB-INF

         http://localhost:8080/2020-1-10webProject/lesson05.jsp

        1.1 If the Jsp in the directory under Webcontent, when accessed by the browser, you can directly access the project name / jsp name

                Such a way that the data page of insecurity

         1.2 If the JSP is the WEB-INF directory, the data on this page is relatively safe, if you want to access the WEB-INF directory of JSP

              Can only be read by forwarding, generally through servlet forwards

For one example: the directory is in the WEB-INF / test.jsp.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
test.....
</body>
</html>


Run shot as follows:

 

 

 

 After adding Servlet:

package web_servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/test.jsp").forward(request, response);
    }
}

After adjusting pass run shot:

Guess you like

Origin www.cnblogs.com/whr-blogs/p/12182233.html