1. Launch Eclipse by double clicking on 'eclipse.exe'
2. You'll be prompted with a dialog box, just click 'Ok'
3. You'll be presented with this window:
4. Lalabas na yung main window talaga. Click on 'File' -> 'New' -> 'Other'. Kagaya nito:
6. Expand the group and select 'Dynamic Web Project'.

8. Put in 'PinoyJavaTutorial' sa Project name' and click 'Finish'. Kagaya nito:

Congratulations! We now have a J2EE project at our Eclipse workspace! :)
10. Right click on the newly created project and select 'New' -> 'Servlet' as shown in the red box below:


13. You'll be presented with the predefined 'HelloWorldServlet.java'
14. Unlike sa usual Java app, yung JVM (Java Virtual Machine) ay hinahanap yung 'main()' na method. Sa servlets, pupunta sya kagad sa 'doGet' or 'doPost' na methods since yung 'main()' method natin ay nasa tomcat na. Bale ganto para malinaw:
usual Java application: JVM -> main method
by servlets: JVM -> tomcat -> doGet or doPost method
Depende kung pano natin sya tinawag, kung 'doGet' or 'doPost' ang gagamitin. In our example, sa 'doGet' sya pupunta kasi ang 'doGet' ang default. Sa mga succeeding lessons na yung difference ng Post and Get. Easy-easy lang muna tayo.
15. Put in the following codes under 'doGet':
PrintWriter pw = response.getWriter();
pw.print("Hello World from Servlet!");
Magkakaroon ng underline na kulay pula yan since PrintWriter is unknown. We need to import pa kasi yung PrintWriter na class. However, since we are using Eclipse, just press 'ctrl + shift + O' para mag-automatically import na sya. Magiging ganto na ang hitsura ng 'doGet' method natin:

17. Expand 'Server' then select 'Server'. Kagaya nito:

19. Expand nyo yung 'Apache' then select 'Tomcat v6.0 Server':

21. Sa next window, browse nyo lang kung san nyo nilagay yung extracted na 'Tomcat'. Yung value nito ay same ng value na nilagay nyo sa 'CATALINA_HOME' nung nag ko-configure tayo before.
22. Click 'Finish'
23. Now, dun sa Project natin, right click, 'Run As' -> 'Run on Server'. Like this:


24. Mag e-error yan since wala pa tayong default na page. Pero try putting in http://localhost:8080/PinoyJavaTutorial/HelloWorldServlet and you'll see this page:

Congratulations! You have now created your first Servlet! I'll explain on my next blog entry, which should be coming the week after next week, on how everything works. :)
No comments:
Post a Comment