A simple Web Application which demonstrate how to develop your first Ajax Application : step-by-step in JSP and Servlets.
1. Create a Simple GetTime.java Servlet -
2. Create a simple getTime.jsp
Output when running getTime.jsp -
As soon as user clicks on GetTime button, Current Date is printed on the textArea without page getting refreshed ...
1. Create a Simple GetTime.java Servlet -
package com.hubberspot.ajax; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; 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("/GetTime") public class GetTime extends HttpServlet { protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // A Simple GetTime Servlet which computes // Todays date and send it as response to // getTime.jsp PrintWriter out = response.getWriter(); Date date = new Date(); out.println(date); } }
2. Create a simple getTime.jsp
|
Output when running getTime.jsp -
As soon as user clicks on GetTime button, Current Date is printed on the textArea without page getting refreshed ...