====== Servlets and JSP ======
===== Servlets =====
A simple "HelloWorld" servlet, that also prints the current date.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("");
out.println("Hello World");
out.println("");
out.println("Hello World
");
out.println("Today is: " + (new java.util.Date().toString()) );
out.println("");
} // doGet
} // HelloWorld
In order to run it, do the following:
- Place it in a file, HelloWorld.java
- Compile it.
- Place the resulting HelloWorld.class file in the "servlets" directory.
- Run it by pointing browser to: http://server.address/servlets/HelloWorld
===== JSP =====
The same page as above using JSP looks as shown below:
Hello World
Hello World
Today is: <%= new java.util.Date().toString() %>
In order to run it, do the following:
- Place it in a file, HelloWorld.jsp in the same directory as your .html files
- Run it by pointing browser to: http://server.address/~youraccount/HelloWorld.jsp