Welcome to Abdul Malik Ikhsan's Blog

Panggil useBean dari servlet

Posted in Tutorial JSP, Tutorial Servlet by samsonasik on August 24, 2007

Masih kelanjutan Cara Compile Extends pada UseBean, jika belum dibaca, harap baca dulu sekarang, kita akan membahas tentang cara memanggilnya pada servlet, kita lanjutkan :
—————
Kita buat file servlet kita, misalkan kita taruh di web-inf\classes\panggilaku\servletpanggil.java
—————

Code:
package panggilaku;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import panggilmahasiswa.panggil;public class servletpanggil extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
panggil x=new panggil();
x.setnama(“samsonasik”);
request.setAttribute(“name”,x.getnama());
request.getRequestDispatcher(“/tampilkan.jsp”).forward(request,response);
}
}

——————-
compile
——————-
membuat mapping servlet udah bisa kan? kalau belum silakan baca dulu, …..
sekarang, kita panggil di file jsp kita (/tampilkan.jsp berarti ada di webapps\tampilkan.jsp)

Code:
Halo ${name}

—–
simple kan …
——–

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: