Source Code Materi II Struktur Servlet Dasar
Source Code Materi II Struktur Servlet Dasar
<%--
Document : index
Created on : Sep 7,
2009, 6:20:34 AM
Author
: dar
--%>
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ini adalah aplikasi web saya yang pertama</title>
</head>
<body>
<h1>Halo dunia..!</h1>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ini adalah aplikasi web saya yang pertama</title>
</head>
<body>
<h1>Halo dunia..!</h1>
</body>
</html>
package package1;
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
/**
*
*
@author dar
*/
public class Servlet1 extends HttpServlet {
/**
* Processes requests
for both HTTP <code>GET</code> and <code>POST</code>
methods.
* @param request
servlet request
* @param response
servlet response
* @throws
ServletException if a servlet-specific error occurs
* @throws IOException
if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// TODO output
your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet
Servlet1</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Servlet1 at " +
request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
//
}
finally
{
out.close();
}
}
// <editor-fold
defaultstate="collapsed" desc="HttpServlet methods. Click on the
+ sign on the left to edit the code.">
/**
* Handles the HTTP
<code>GET</code> method.
* @param request
servlet request
* @param response
servlet response
* @throws
ServletException if a servlet-specific error occurs
* @throws IOException
if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP
<code>POST</code> method.
* @param request
servlet request
* @param response
servlet response
* @throws
ServletException if a servlet-specific error occurs
* @throws IOException
if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short
description of the servlet.
* @return a String
containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
<%--
Document : HaloJSP
Created on : Sep 7,
2009, 4:17:02 PM
Author : dar
--%>
<%@page contentType="text/html"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>Halaman JSP</title>
</head>
<body>
<h1>Halo apakabar</h1>
<h1>Akuberhasilmembuatjsp</h1>
</body>
</html>
<?xml version="1.0"
encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>package1.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/Servlet1</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>HaloJSP.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0"
encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>package1.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/Servletku</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>HaloJSP.jsp</welcome-file>
</welcome-file-list>
</web-app>
nih klo yang mau download file nya http://www.4shared.com/zip/yxAfoBmg/154808210912Source_Code_Materi.html
0 komentar: