chat
This commit is contained in:
@@ -1,10 +1,55 @@
|
||||
package pr.tp.web.servlet;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.w3c.dom.html.HTMLImageElement;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@WebServlet("/chat")
|
||||
public class Chat extends HttpServlet {
|
||||
private static final long serialVersionUID = 197811968639586823L;
|
||||
private StringBuffer chatContent;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("text/html");
|
||||
PrintWriter out = response.getWriter();
|
||||
chatContent = new StringBuffer();
|
||||
chatContent.append("Bienvenue sur le chat").append("\n");
|
||||
chatContent.append("Soyez polis").append("\n");
|
||||
chatContent.append("<pre>" +
|
||||
"ligne 1" +
|
||||
"\n" +
|
||||
"ligne 2" +
|
||||
"</pre>" );
|
||||
chatContent.append("<form name=\"chatForm\" action=\"chat\" method=\"post\">");
|
||||
chatContent.append("<input type=\"text\" name=\"ligne\" value=\"\"/>");
|
||||
chatContent.append("<input type=\"submit\" name=\"action\" value=\"submit\"/>");
|
||||
|
||||
chatContent.append("<input type=\"submit\" name=\"action\" value=\"refresh\"/>");
|
||||
chatContent.append("</form>");
|
||||
|
||||
String action = request.getParameter("action");
|
||||
if (action != null && action.equals("submit")) {
|
||||
String ligne = request.getParameter("ligne");
|
||||
if(ligne != null) {
|
||||
chatContent.append("<body>").append(ligne).append("----------").append(LocalTime.now());
|
||||
chatContent.append("</body>");
|
||||
}
|
||||
}
|
||||
if (action != null && action.equals("refresh")) {
|
||||
chatContent.append("refresh");
|
||||
}
|
||||
out.println(chatContent.toString());
|
||||
}
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user