Java Servlets BSIT-Sem-5
th
Web Technologies
Prof. Usman Ahmad, Govt. Islamia Graduate College, Gujranwala.
Java Servlets
Example 1:
Index.html
<html><body>
<form action="welcome" method="get">
<input type="submit" value="Press to Run Servlet" >
</form>
</body></html>
First.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class First extends HttpServlet{
public void doGet(HttpServletRequest req ,HttpServletResponse res )throws ServletException,IOException
{
// Set response content type
res.setContentType("text/html");
// Actual logic goes here.
PrintWriter pw=res.getWriter();
pw.println("<h1>Welcome</h1>Welcome to Java Servlet .");
}
}
Web.xml
<web-app>
public void doGet(HttpServletRequest request , HttpServletResponse response ) throws ServletException, IOException {
// Set response content type
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Using GET Method to Read Form Data" ;