Servlet parameter : Basics « Servlets « Java






Servlet parameter

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ShowFile extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    String fileName = request.getParameter("file");

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Welcome</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h2>The File</h2>");
    out.println(fileName);
    out.println("</body>");
    out.println("</html>");
    out.close();

  }

  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
  }
}

           
       








Related examples in the same category

1.Using Init Method Servlet
2.Bean Parser Servlet
3.Post Handler
4.Query Modifier
5.Compression Response Stream servlets
6.Compression Servlet Response Wrapper