servlet 和 jsp 显示相同的信息?
servlet and jsp displaying same information?
目前我正在尝试将来自我的 java servlet 的信息显示到它的相关 jsp 页面。但是,当我 运行 程序时,jsp 文件的预期输出显示在 servlet 目录中。
在视觉上,Display.jsp 页面:
和 \ServerToRun(应该显示空白屏幕的 Servlet 页面):
因此我的问题是,
Why is the content of /Display.jsp appearing in /ServerToRun?
这是 ServerToRun class 的 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>
感谢任何帮助。
因为您正在从 servlet 重定向到 Display.jsp。尝试在 JSP 中添加任何动态内容并执行两者,只有 servlet 才能显示动态内容。!
我想我明白你的问题了。你说的是目录。
在您的 URL 中,路径(/Grief_UI/Display.jsp 和 /Grief_UI/ServletToRun)与文件夹无关。
它是URL的一个结构元素。有时您甚至没有像这些路径元素那样命名的文件。该路径通常由 Servlet 处理,用户有使用文件夹的感觉,是的,但这只是对资源本地化的描述。
是因为您的 servlet 捕获了所有请求,您应该注意您在 ServerToRun.java class 中放置了哪个注释,或者是否在显示描述符中放置了注释 (web.xml) servlet 的注释。
目前我正在尝试将来自我的 java servlet 的信息显示到它的相关 jsp 页面。但是,当我 运行 程序时,jsp 文件的预期输出显示在 servlet 目录中。
在视觉上,Display.jsp 页面:
和 \ServerToRun(应该显示空白屏幕的 Servlet 页面):
因此我的问题是,
Why is the content of /Display.jsp appearing in /ServerToRun?
这是 ServerToRun class 的 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>
感谢任何帮助。
因为您正在从 servlet 重定向到 Display.jsp。尝试在 JSP 中添加任何动态内容并执行两者,只有 servlet 才能显示动态内容。!
我想我明白你的问题了。你说的是目录。
在您的 URL 中,路径(/Grief_UI/Display.jsp 和 /Grief_UI/ServletToRun)与文件夹无关。
它是URL的一个结构元素。有时您甚至没有像这些路径元素那样命名的文件。该路径通常由 Servlet 处理,用户有使用文件夹的感觉,是的,但这只是对资源本地化的描述。
是因为您的 servlet 捕获了所有请求,您应该注意您在 ServerToRun.java class 中放置了哪个注释,或者是否在显示描述符中放置了注释 (web.xml) servlet 的注释。