我正在尝试应用以下示例。我在一本关于servlet的书中找到了它,但是IDE给了我错误信息“servlet tag is unknown”。
你能帮我找到错误吗?注意:HTML文件保存为.shtml。
<HTML>
<HEAD><TITLE>Times!</TITLE></HEAD>
<BODY>
The current time here is:
<SERVLET code="CurrentTime">
</SERVLET>
<P>
The current time in London is:
<SERVLET code="CurrentTime">
<PARAM name="zone" value="GMT">
</SERVLET>
<P>
And the current time in New York is:
<SERVLET code="CurrentTime">
<PARAM name="zone" value="EST">
</SERVLET>
<P>
</BODY>
</HTML>
这是servlet文件
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Hello
*/
@WebServlet("/CurrentTime")
public class CurrentTime extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public CurrentTime() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
PrintWriter out = res.getWriter();
Date date = new Date();
DateFormat df = DateFormat.getInstance();
String zone = req.getParameter("zone");
if (zone != null) {
TimeZone tz = TimeZone.getTimeZone(zone);
df.setTimeZone(tz);
}
out.println(df.format(date));
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
结果是时间没有显示