04.06.2017 Views

servlets_tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java Servlets<br />

import javax.servlet.*;<br />

import javax.servlet.http.*;<br />

import java.util.*;<br />

// Extend HttpServlet class<br />

public class ReadParams extends HttpServlet {<br />

// Method to handle GET method request.<br />

public void doGet(HttpServletRequest request,<br />

HttpServletResponse response)<br />

throws ServletException, IOException<br />

{<br />

// Set response content type<br />

response.setContentType("text/html");<br />

PrintWriter out = response.getWriter();<br />

String title = "Reading All Form Parameters";<br />

String docType =<br />

"\n";<br />

out.println(docType +<br />

"\n" +<br />

"" + title + "\n" +<br />

"\n" +<br />

"" + title + "\n" +<br />

"\n" +<br />

"\n" +<br />

"Param NameParam Value(s)\n"+<br />

"\n");<br />

Enumeration paramNames = request.getParameterNames();<br />

while(paramNames.hasMoreElements()) {<br />

String paramName = (String)paramNames.nextElement();<br />

out.print("" + paramName + "\n");<br />

String[] paramValues =<br />

21

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!