Created
September 10, 2012 09:42
-
-
Save lalyos/3689970 to your computer and use it in GitHub Desktop.
servlet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme.servlet; | |
import java.io.IOException; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
/** | |
* Servlet implementation class CoffeServlet | |
*/ | |
public class CoffeServlet extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |
/** | |
* @see HttpServlet#HttpServlet() | |
*/ | |
public CoffeServlet() { | |
super(); | |
// TODO Auto-generated constructor stub | |
} | |
/** | |
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse | |
* response) | |
*/ | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
Date now = new Date(); | |
Date coffee = null; | |
try { | |
coffee = sdf.parse(getInitParameter("coffeeTime")); | |
} catch (ParseException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
long minutesLeft = (coffee.getTime() - now.getTime()) / 60000; | |
response.getOutputStream().println("<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Servlet Training</title></head><body>"); | |
response.getOutputStream().println("Minutes left till coffee break: " + minutesLeft); | |
response.getOutputStream().println("</body></html>"); | |
} | |
/** | |
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse | |
* response) | |
*/ | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, | |
IOException { | |
// TODO Auto-generated method stub | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com; | |
import javax.servlet.*; | |
import javax.servlet.http.*; | |
public class FirstServlet extends HttpServlet { | |
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { | |
resp.getOutputStream().println("my first servlet ..."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> | |
<display-name>servlet-training</display-name> | |
<welcome-file-list> | |
<welcome-file>index.html</welcome-file> | |
<welcome-file>index.htm</welcome-file> | |
<welcome-file>index.jsp</welcome-file> | |
<welcome-file>default.html</welcome-file> | |
<welcome-file>default.htm</welcome-file> | |
<welcome-file>default.jsp</welcome-file> | |
</welcome-file-list> | |
<servlet> | |
<description></description> | |
<display-name>FirstServlet</display-name> | |
<servlet-name>FirstServlet</servlet-name> | |
<servlet-class>com.acme.servlet.FirstServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>FirstServlet</servlet-name> | |
<url-pattern>/servlets/first</url-pattern> | |
</servlet-mapping> | |
<servlet> | |
<description></description> | |
<display-name>CoffeServlet</display-name> | |
<servlet-name>CoffeServlet</servlet-name> | |
<servlet-class>com.acme.servlet.CoffeServlet</servlet-class> | |
<init-param> | |
<param-name>coffeeTime</param-name> | |
<param-value>2012-09-10 15:45</param-value> | |
</init-param> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>CoffeServlet</servlet-name> | |
<url-pattern>/coffee</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment