Skip to content

Instantly share code, notes, and snippets.

@wmcu
Created March 17, 2015 06:12
Show Gist options
  • Save wmcu/495e9493910ba196c873 to your computer and use it in GitHub Desktop.
Save wmcu/495e9493910ba196c873 to your computer and use it in GitHub Desktop.
Servlet Example
package me.simpleweb2;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet extends HttpServlet {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 2249960422183442326L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String email = req.getParameter("email");
String ip = req.getRemoteHost();
resp.getWriter().println("<html>");
resp.getWriter().println("<head>");
resp.getWriter().println("<title>This is the response</title>");
resp.getWriter().println("</head>");
resp.getWriter().println("<body>");
resp.getWriter().println("Your name is :" + name + "<br>");
resp.getWriter().println("Your email is :" + email + "<br>");
resp.getWriter().println("Your ip is :" + ip);
resp.getWriter().println("</body>");
resp.getWriter().println("</html>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment