Source Code Materi V Server Response dan Cara Kerja dari HTTPServlet Response

22.55 priyoh 0 Comments

Source Code Materi V Server Response dan Cara Kerja dari HTTPServlet Response

Nih file nya http://www.4shared.com/zip/EVdzgtbe/363202191012Materi_V_Server_Re.html



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method="post" action="Action">
<table border="1">
<tr>
<td>Nama</td>
<td><input type="text" name="nama" id="nama"></td>
</tr>
<tr>
<td>Umur</td>
<td><input type="text" name="umur" id="umur"></td>
</tr>
<tr>
<td>BahasaPemrograman</td>
<td>
<input type="checkbox" name="bahasa" value="C">C <br>
<input type="checkbox" name="bahasa" value="C++">C++ <br>
<input type="checkbox" name="bahasa" value="Java">Java <br>
<input type="checkbox" name="bahasa" value="JSP">JSP <br>
<input type="checkbox" name="bahasa" value="VB6">VB6 <br>
<input type="checkbox" name="bahasa" value="VB.Net">VB.Net <br>
<input type="checkbox" name="bahasa" value="PHP">PHP <br>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="OK">
</td>
</tr>
</table>
</form>
</body>
</html>

package servlet;

importjava.io.IOException;
importjava.io.PrintWriter;
importjava.util.Enumeration;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class ServletAction extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throwsServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();

out.print("getCharacterEncoding : " + response.getCharacterEncoding() + "<br>");
out.print("getLocale : " + response.getLocale() + "<br>");
out.print("getContentType : " + response.getContentType() + "<br>");
out.print("getBufferSize : " + response.getBufferSize() + "<br>");
out.print("<br><br>");
out.print("getMethod : " + request.getMethod() + "<br>");
out.print("getRequestURI : " + request.getRequestURI() + "<br>");
out.print("getRequestURL : " + request.getRequestURL() + "<br>");
out.print("getProtocol : " + request.getProtocol() + "<br>");
out.print("getRemoteAddr : " + request.getRemoteAddr() + "<br>");
out.print("getRemotePort : " + request.getRemotePort() + "<br>");
out.print("getServerName : " + request.getServerName() + "<br>");
out.print("getServerPort : " + request.getServerPort() + "<br>");
out.print("getServletPath : " + request.getServletPath() + "<br>");
out.print("getContentType : " + request.getContentType() + "<br><br>");

        Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements())
        {
            String header = (String) headerNames.nextElement();
out.print(header + " : " + request.getHeader(header) + "<br>");
        }

out.print("<br>nama : " + request.getParameter("nama") + "<br>");
out.print("umur : " + request.getParameter("umur") + "<br><br>");

        Enumeration paramName=  request.getParameterNames();
while(paramName.hasMoreElements())
        {
            String name = (String) paramName.nextElement();
out.println("nama parameter : " + name + "<br>");
        }

        String allValues[] = request.getParameterValues("bahasa");
for(int i=0; i<allValues.length; i++)
        {
out.println("bahasake - " + (i+1) + " = " + allValues[i] + "<br><br>");
        }
    }
    }
}

<servlet>
<servlet-name>ServletAction</servlet-name>
<servlet-class>servlet.ServletAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletAction</servlet-name>
<url-pattern>/Action</url-pattern>
</servlet-mapping>


0 komentar: