-2

I tried to make a simple Java Servlet app, that displays the date and time. The problem is: it won't show up when I load the page(the page itself does show up). I have debugged it, and the date and time does show up in the console.

TestServlet.java(not the whole file):

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date timeDate = new Date();
    @SuppressWarnings("unused")
    String time = format.format(timeDate);


    request.getRequestDispatcher("/WEB-INF/test.jsp").forward(request, response);

}

test.jsp(whole file):

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <h1>Welcome! It is ${time}!</h1>
    </body>
</html>

All help is welcome ;)

Tom
  • 39
  • 1
  • 6

1 Answers1

-1

Got it working! I had seen a video where they did it like I did in the question. Now I looked at the link that AxelH gave me(where I looked earlier, but thought that it didn't anwser my question) and found an answer!

For anyone that also got the problem: I had to set it as an attribute in the request, like this:

request.setAttribute("name", "value");

Then I could use it in the jsp file ;)

Tom
  • 39
  • 1
  • 6