Created
January 22, 2020 21:21
-
-
Save usptact/34c9345a231e4cc11202893cafa76c14 to your computer and use it in GitHub Desktop.
HelloServlet
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
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.annotation.WebServlet; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
@WebServlet(name = "HelloServlet", urlPatterns = {"hello"}, loadOnStartup = 1) | |
public class HelloServlet extends HttpServlet { | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
response.getWriter().print("Hello, World!"); | |
} | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
String name = request.getParameter("name"); | |
if (name == null) name = "World"; | |
request.setAttribute("user", name); | |
request.getRequestDispatcher("response.jsp").forward(request, response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment