目前,我正在尝试将信息从我的 java servlet 显示到其相关的 jsp 页面。但是,当我运行该程序时,jsp 文件的预期输出显示在 servlet 目录中。
和\ServerToRun(应该显示空白屏幕的 Servlet 页面):
因此我的问题是,
Why is the content of /Display.jsp appearing in /ServerToRun?
以下是 ServerToRun 类的 doPost()
代码:
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
CSVFileOperations csvfo = new CSVFileOperations();
String url = "/Display.jsp";
response.setContentType("text/html");
String header = csvfo.getHeaders().remove();
System.out.println(header);
request.setAttribute("header", header);
request.getServletContext().getRequestDispatcher(url).
forward(request, response);
}
以及 Display.jsp 的标记:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>OTS Grief</title>
</head>
<body>
${header}<br>
Test Why is his showing up in ServerToRun?
</body>
</html>
感谢任何帮助。
最佳答案
我想我理解你的问题。您正在谈论目录。
在您的 URL 中,路径(/Grief_UI/Display.jsp 和/Grief_UI/ServletToRun)不一定与文件夹相关。
它是 URL 的结构元素。有时您甚至没有像这些路径元素那样命名的文件。路径通常由 Servlet 处理,用户会感受到使用文件夹的感觉,是的,但这只是对资源本地化的描述。
关于java - servlet 和 jsp 显示相同的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57245353/