Total Pageviews

Friday, October 8, 2010

Getting up to speed towards building websites using Java technology.
This is a simple tutorial that demonstrates the usage of jsp/servlets approach for building simple dynamic websites.
I am using the foll. Tools :
Netbeans IDE
Tomcat – A servlet/JSP container
First, start up your netbeans IDE













Setting up Application Server
Here, ensure that you have your server setup correctly. On my instance, I have various servers; ranging from simple ones such as Tomcat to complete Java EE servers like Glassfish & Jboss. Also, there are servers for Rails applications. But we'll be only using Tomcat as of now.














Start the server by right-clicking the server node and hitting start. After a successful start, you'd get a following message on the server console : INFO: Server startup in XXX ms.
This means that our server is up and running.

Creating a Web Application
Now create a new web project.


Next choose the Tomcat server.
Leave the context path on the server as the default one now.
Since, we are creating a simple application, do not choose any framework now.
After the project gets created, write down the following on the index.jsp file that is displayed.





This is the dynamic statement that we've created through jsp.
Now hit F6 or the > Button




See the output on the web browser.
Congratulations!

Building Servlets

Now, we'll get our hands dirty with servlets.
Remember, all the JSP pages ultimately get converted into servlets at runtime and knowledge of servlets is key towards building a complete web application.
Now, create a new servlet through right-clicking the project name & selecting the Servlet entry.









Here, let's name it SimpleServlet and put it in a package, bbdnitm.tgmc







Hit the finish button.
Now, edit the servlet class file as:

Next, open up WEB-INF/web.xml file and select xml view from the main tab


This is called the deployment descriptor and is the MAIN file of any java web application. It is similar to web.config file of an asp.Net application.
Here, inside the <web-app> root tag, you'll see the foll. Code generated
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>bbdnitm.tgmc.SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServlet</url-pattern>
</servlet-mapping>
This is the configuration details of our servlet. The <servlet-name> performs a mapping between <servlet-class> (the class file) and <url-pattern> (the actual web request) tags.

Finally hit the run (F6) button to deploy your updated site on the server. If all is well, then you should see the following on your web browser:





That's it! You now know the very basics of a java based web application and now you can go on further.
Further Actions:

To continue, I'll request you/ your team the following paths
  • Continue learning jsp via books/tutorials. More specifically, learn
  • Sessions
  • HTML Form submissions
  • <jsp> tags
  • error handling/debugging on jsp pages
  • Learn more about Enterprise java – it was known as j2ee 1.3, j2ee 1.4 earlier and now as Java EE 5 & 6.
  • Enhance your knowledge about Tomcat Server (its catalina servlet container & jasper engine)
  • TGMC Specific tools for further development -> RAD as an IDE and WebSphere App.Server

Thanks in advance!










No comments:

Post a Comment