Sunday 22 February 2009

Good film : Breakaway

Monday 9 February 2009

Servlet and JSP doLogin

Download the entire project here
The file exercise.rar contains JSP and Servlet code. I hope you can try this at home!
You'll see that there is only a little differencies using JSP or Servlet. I actually use the same logic for the project! If you use JSP , then the logic code will be placed in a file .jsp or if you use Servlet, your logic code will be placed in a file .class.
Sorry, I don't have enough time to explain it by detail now.
Any question? Just post a comment here or chat with me!

Friday 6 February 2009

Servlet Basic Tutorial

This is the Servlet Basic tutorial. I'll guide you to run your first Servlet through the rest of this post.
First of all, you have to install java. You can download the latest Java version from here
I use Apache Tomcat for the server which you can download it here then install both of them to your computer.

After installing(I assume that you install both to their default path installation), you can begin editing your first servlet. To make it easier, I use template for Servlet class. The template will look like this :

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

//MyServet is the class name
public class MyServlet extends HttpServlet{

//Method for handling Get
//Default method is Get
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

response.setContentType("text/html"); // this should be called first

PrintWriter out = response.getWriter(); // Returns a PrintWriter

out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>");

//Logic goes here
//Example :
out.println("<font color='blue'>");
out.print("Hello Word");
out.println("</font>");

out.println("</body>");
out.println("</html>");

out.close();

}

//Method for handling Post
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//you can leave it blank , if you don't use post method
}

}

From the root server directory, the default root directory is "webapps" or in the absolute path "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps" if your Tomcat version is 5.X. Make a new folder,name it "exercise". Now, in webapps folder, there is a folder named "exercise". Create the file structure like this :
>exercise(directory)
--->WEB-INF(directory)
------>web.xml(file)
------>classes(directory)
------>MyServlet.java(file)
------>servlet-api.jar(file)
------>lib(directory)

You can download servlet-api.jar here

Open MyServlet.java with your favorite editor. I use notepad++ in this tutorial which you can also download it here
Now, we'll make the classical "Hello World" application to your first servlet. Just copy and paste the code to your editor. After it, save the file.

Open web.xml, copy the following code to that file then save.

<web-app>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
</web-app>

The java source code(MyServlet.java) is now ready to be compiled. The question is "How can I compile the file?"
You can compile it by using your commmand prompt. I use Windows XP for the operating system.
Before you start, you must set the Environment variable path. You can do this by going to Control Panel -> System -> click Advanced tab then edit Path variable by adding this code ";C:\Program Files\Java\jdk1.6.0_07\bin;" (without double quotes) then OK and OK and OK. The code you can get it by exploring Java folder, every Java version can have a different path, so you must get the path by yourself. I just give you my Java path.

Let's move on! You can open the command prompt by pressing Windows + R and then you type "cmd" (without double quotes) then press ENTER.
Now, the command prompt window is opened. Then type "CD C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\exercise\WEB-INF\classes" (depends on the server installation path) then press ENTER. Type "javac -cp .;servlet-api.jar MyServlet.java" then press ENTER. You'll see that if there are no error, the new file MyServlet.class will be generated by that process. So that, in you classes folder, there are MyServlet.java, servlet-api.jar,MyServlet.class.

Run the Tomcat server now. I know you can run the server , so I don't explain it here. Open your browser, type
"http://localhost:8080/exercise/MyServlet" (without double quotes) , then press ENTER. You'll see the "Hello World" and the color of that words is BLUE. Please remember that any changes you made to MyServlet.java, after you compiled it, you must restart the server to make effects.

You can download the entire project here

Great! You've already run your first Servlet ever! Thank you for reading this tutorial, I hope you can enjoy! If there are problems you can post comments or chat with me!

Wednesday 4 February 2009

Automata Theory

Kisi kisi tba 2009
1. a,b. Finite Automata dengan Output
Kisi - kisi : Soal Teori mengenai Moore Machine
2. a,b. Regular Expression vs CFG
Kisi - kisi : Diketahui RE, ditanya NFA dan CFG
3. a,b. CFG
Kisi - kisi : Diketahui CFG, ditanya CGF no useless symbol dan CNF
4. CFG
Kisi - kisi : Diketahui CFG, ditanya GNF
5. a,b. Push Down Automata
Kisi - kisi : Diketahui PDA, ditanya ID dan bentuk umum bahasa

Contoh soal :

Grammar G = {{S,A,B,C,D},{a,b},P,S}
dengan produksi P:
S -> aA | BD C -> b | bS | aAA
A -> a | aS | bCC D -> bD | DB
B -> aB | BD
Tuliskan grammar G1 (ekuivalen G) yang tidak mengandung useless symbol.


Cari bentuk Chomsky Normal Form (CNF) untuk grammar berikut :
S -> AB | CA
A -> a
B -> BC | AB
C -> aB | b


Diketahui CFG G = ({S,A,B},{a,b},P,S)
dimana P terdiri dari :
1. S -> bA
2. S -> aB
3. A -> bAA
4. A -> aS
5. A -> a
6. B -> aBB
7. B -> bS
8. B -> b
Diminta:
Buatlah bentuk Chomsky Normal Form dari CFG di atas.


Diketahui suatu Grammar G = ({A1, A2, A3}, {a, b}, P, A1)
dimana P terdiri dari :
1. A1 -> A2 A3
2. A2 -> A3 A1 | b
3. A3 -> A1 A2 | a
Diminta:
Buatlah bentuk Greibach Normal Form dari CFG di atas.


Diketahui suatu Push Down Automata (PDA) dengan Grammar
M = ({q1, q2}, {0, 1, c}, {M, B, H}, "symbol delta", q, M, "symbol himpunan kosong") dan mekanisme kerja digambarkan dalam tabel berikut :

Buatlah Langkah-langkah PDA diatas bila diberikan string input : 0011100