Add.java @WebServlet( urlPatterns={"/add"}) public class Add extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws IOException { int i=Integer.parseInt(req.getParameter("num1")); int j=Integer.parseInt(req.getParameter("num2")); int k=i+j; PrintWriter out=res.getWriter(); out.println(k); } } index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Add numbers</title> </head> <body> <form action="add" method="get"> enter num1:<input type="text" name="num1"><br> Enter num2:<input type="text" name="num2"> <br> <input type="submit" value="Add"> </form> </body> </html>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter