Servlet 3 – Contoh Hello World


Project Servlet 3 ini membutuhkan Java Enterprise Edition versi 3, Anda perlu menggunakan Application Server atau Web Server yang sudah mendukung Servlet 3, seperti Glassfish 3, JBoss 6 atau Apache Tomcat 7.

package khannedy.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "HelloWorld", urlPatterns = {"/HelloWorld"})
public class HelloWorldServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        writer.write("Hello World");
        writer.close();
    }
}

Hasilnya :

Screenshot-localhost:8080-WebApplication-HelloWorld - Google Chrome

Screenshot-localhost:8080-WebApplication-HelloWorld - Google Chrome

Selamat mencoba 😀

Iklan

5 pemikiran pada “Servlet 3 – Contoh Hello World

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s