web.xml配置
DateServlet.class
public class DateServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String data = sdf.format(date);
resp.getOutputStream().write(data.getBytes());
}
}
web.xml
<servlet>
//定义servlet的名字
<servlet-name>dateServlet</servlet-name>
//Tomcat会根据该值反射创建servlet对象
<servlet-class>com.neu.day01.DateServlet</servlet-class>
</servlet>
//配置当前servlet能处理怎样的url请求
<servlet-mapping>
<servlet-name>dateServlet</servlet-name>
<url-pattern>/dateServlet</url-pattern>
</servlet-mapping>
结果
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。