I have a few html files each of them containing the components of my future web page. I want them to be shown if user was looking for them. But how can I show many html files together in servlet response? As I know, the code below can redirect user to only one html file.
RequestDispatcher rd = request.getRequestDispatcher("/index.html");
rd.forward(request, response);
response.sendRedirect("/index.html");
I tried to use IO streams:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<String> content = new ArrayList<String>();
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("/header.html")));
while ((str = in.readLine()) != null) {
content.add(str);
}
PrintWriter out = response.getWriter();
for (String item: content) {
out.println(item);
}
}
But it gives me only java.io.FileNotFoundException:header.html. Browser says: "HTTP Status 500 - Internal Server Error". How can I solve this? Should use another way?