Reputation: 867
Currently I am trying to display information from my java servlet over to its related jsp page. However, when I run the program, the expected output of the jsp file is displayed in the servlet directory.
Visually, the Display.jsp page:
And \ServerToRun (The Servlet page that should display a blank screen):
Thus my question is,
Why is the content of /Display.jsp appearing in /ServerToRun?
Here is the code for doPost()
of the ServerToRun class:
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);
}
And the markup for 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>
Any help is appreciated.
Upvotes: 0
Views: 213
Reputation: 1
Is because your servlet is trapping all requests, you should notice which annotation you are putting in your ServerToRun.java class or if you are putting in the display descriptor (web.xml) the annotations of the servlet.
Upvotes: 0
Reputation: 1266
I think I understand your question. You're talking about directories.
In your URL, the path (/Grief_UI/Display.jsp and /Grief_UI/ServletToRun) is not necessary related to folders.
It is a structuring element of the URL. Sometimes you don't even have files that are named like these path elements. The path gets normally processed by a Servlet and the user gets the feeling of using folders, yes, but it is only a description for the localising the resources.
Upvotes: 2
Reputation: 8322
Because from servlet you are redirecting to Display.jsp. Try adding any dynamic content in JSP and execute both, only servlet would be able to display the dynamic content.!
Upvotes: 1