Learn Java Servlets

After Tomcat Setup Download falkner bookand Go through . This is the best book for beginners which is free to download from theserverside.com. Or else Head first Servlets and Jsps By Kathy sierra and Bert Bates is also a good book to start.
First page with tomcat :
The directory structure of a trivial web application looks like this.full_webapp_dir_structure.jpg
1) so Create a directory ‘sample’ in tomcat-home/webapps directory and in that create sub dir WEB-INF
2)create web.xml in WEB-INF folder and put the below line
<web-app></web-app>
3)create sample.xml in tomcat-home/webapps folder and type the below code.
<context path=”sample” docBase=”sample” debug=”0″/>
4)create index.html in sample directory
<html><body>helloworld</body></html>
5)restart tomcat
6)open http://127.0.0.1:8888/sample  It will display helloworld message.

TomcatPlugin for Eclipse
1) Download TomcatPlugin for eclipse , I downloaded version 3.0 tomcatPluginV3.zip
2) Unzip it under eclipse/plugins/ directory
3) Select menu ‘Window->Customize Perspective…’, expand ‘Others’ and check ‘Tomcat’
4) Select menu ‘Window->Customize Perspective…->Commands’, and check ‘Tomcat’ in ‘Available command groups’
5) Set Tomcat home : Window -> Preferences, select Tomcat and set Tomcat home(where you downloaded)
6) This plugin launches Tomcat using the default JRE checked in Eclipe preferences window.
To set a JDK as default JRE for Eclipse open the preference window :
Window -> Preferences -> Java -> Installed JREs.
This JRE must be a JDK (This is a Tomcat prerequisite).
 This will complete the process of configuring Tomcat plugin for Eclipse from Now on we can directly create new tomcat project by button clicks avoiding creating directory structure and all like this  Eclipse->file->new->tomcat project

JDBC in Servlets
1) Place the oracle dirvers jar(odbc14.jar see JDBC post if you have not installled these drivers yet) file in WEB-INF/lib folder
2) Set the buildpath right click on the project ->Properties->javabuildpath->add jars->select oracledriver jar file.
servlets does not recognize zip file so make the zip file to jar file using jar utility
All the packages under the jar must begin with oracle. * .if not the JDBC project will not work.
Assignments
1) Hello world to start with.
2) Select records from a table and print them on screen like select StudentNo,name from database and display it on jsp.
3) Select any file from ur filesystem using html and print the content of the file on screen using servlet.
4) Create a simple HTML form that calls your servlet using an action of “get”. See if it calls the servlet correctly. Change the action to “post” and re-submit. Make sure you understand the outcome.
5)try all the examples in falkner book
6)try some examples using Weblogic/Websphere server

Published in: on December 21, 2006 at 9:27 am  Leave a Comment  

The URI to TrackBack this entry is: https://klavanya.wordpress.com/2006/12/21/learn-java-servlets/trackback/

RSS feed for comments on this post.

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: