Last active
March 8, 2023 14:51
-
-
Save leofernandesmo/90a47c99484ede79b3af982ccb31a672 to your computer and use it in GitHub Desktop.
This file contains 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' ?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Formulário de Exemplo</title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<h1>Form Example</h1> | |
<form method="post" action="meuform"> | |
<label for="caixa-texto">Name:</label> | |
<input type="text" id="caixa-texto" name="caixa-texto"><br> | |
<label for="lista-selecao">Lista de Seleção:</label> | |
<select id="lista-selecao" name="lista-selecao"> | |
<option value="opcao1">Opção 1</option> | |
<option value="opcao2">Opção 2</option> | |
<option value="opcao3">Opção 3</option> | |
</select><br> | |
<p>Please select your age:</p> | |
<input type="radio" id="age1" name="age" value="30"> | |
<label for="age1">0 - 30</label><br> | |
<input type="radio" id="age2" name="age" value="60"> | |
<label for="age2">31 - 60</label><br> | |
<input type="radio" id="age3" name="age" value="100"> | |
<label for="age3">61 - 100</label><br><br> | |
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike"> | |
<label for="vehicle1"> I have a bike</label><br> | |
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car"> | |
<label for="vehicle2"> I have a car</label><br> | |
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat"> | |
<label for="vehicle3"> I have a boat</label><br><br> | |
<input type="submit" value="Enviar"> | |
</form> | |
</body> | |
</html> |
This file contains 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 br.edu.ifal.pweb01; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.Optional; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.ConcurrentMap; | |
import jakarta.servlet.ServletException; | |
import jakarta.servlet.annotation.WebServlet; | |
import jakarta.servlet.http.HttpServlet; | |
import jakarta.servlet.http.HttpServletRequest; | |
import jakarta.servlet.http.HttpServletResponse; | |
@WebServlet(name = "DNS Servlet", urlPatterns = "/dns/*") | |
public class DNSServlet extends HttpServlet { | |
// Map to store the IP mapped by domainName | |
private ConcurrentMap<String, String> ipMap; | |
public void init() throws ServletException { | |
ipMap = new ConcurrentHashMap<>(); | |
} | |
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
String domainName = req.getParameter("domainName"); | |
String ip = req.getParameter("ip"); | |
// In case of any value be null a HTTP status is returned to client. | |
if (domainName == null || ip == null) { | |
resp.sendError(HttpServletResponse.SC_BAD_REQUEST); | |
return; | |
} | |
ipMap.put(domainName, ip); | |
// A HTTP status is returned to client | |
resp.setStatus(HttpServletResponse.SC_CREATED); | |
} | |
} | |
This file contains 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 br.edu.ifal.pweb01; | |
import java.io.IOException; | |
import jakarta.servlet.ServletException; | |
import jakarta.servlet.annotation.WebServlet; | |
import jakarta.servlet.http.HttpServlet; | |
import jakarta.servlet.http.HttpServletRequest; | |
import jakarta.servlet.http.HttpServletResponse; | |
@WebServlet(name = "FormularioSerlvet", value = "/meuform") | |
public class FormularioServlet extends HttpServlet{ | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
req.getRequestDispatcher("basicform.html").forward(req, resp); | |
} | |
@Override | |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
for (String key : req.getParameterMap().keySet()) { | |
System.out.println(key); | |
System.out.println(req.getParameter(key)); | |
} | |
resp.getWriter().println("Recebemos sua solicitação."); | |
} | |
} |
This file contains 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 br.edu.ifal.pweb01; | |
import jakarta.ws.rs.GET; | |
import jakarta.ws.rs.Path; | |
import jakarta.ws.rs.PathParam; | |
import jakarta.ws.rs.Produces; | |
import jakarta.ws.rs.QueryParam; | |
import jakarta.ws.rs.core.MediaType; | |
@Path("/novomundo") | |
public class NovoMundoEndPoint { | |
@GET | |
@Produces(MediaType.TEXT_PLAIN) | |
@Path("/{name}") | |
public String mensagem(@PathParam("name") String nome, @QueryParam("language") String lingua) { | |
return "Ola " + nome + " você fala " + lingua; | |
} | |
} |
This file contains 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 br.edu.ifal.pweb01; | |
import java.io.IOException; | |
import jakarta.servlet.ServletException; | |
import jakarta.servlet.annotation.WebServlet; | |
import jakarta.servlet.http.HttpServlet; | |
import jakarta.servlet.http.HttpServletRequest; | |
import jakarta.servlet.http.HttpServletResponse; | |
@WebServlet(name = "HelloWorld", value = "/helloworld") | |
public class OlaMundoServlet extends HttpServlet{ | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
resp.getWriter().println("Você fez um GET"); | |
} | |
@Override | |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
resp.getWriter().println("Você fez um POST"); | |
} | |
@Override | |
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
resp.getWriter().println("Você fez um PUT"); | |
} | |
@Override | |
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
resp.getWriter().println("Você fez um DELETE"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment