-2
我試圖製作一個簡單的Java Servlet應用程序,它顯示日期和時間。 問題是:當我加載頁面時,它不會顯示(頁面本身顯示)。我已經對它進行了調試,日期和時間確實顯示在控制檯中。變量未顯示Java Servlets
TestServlet.java(而不是整個文件):
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的(整個文件):
<%@ 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>
所有幫助是值得歡迎;)
也許把時間放在一個範圍內;這只是'doGet'中的一個局部變量。 –
下次做一些研究;)[這裏是一個很好的例子](http://stackoverflow.com/a/3609046/4391450) – AxelH