Servlet Getting Started

Servlet Getting Started

This part of the servlet tutorial is to setup the development environment required to execute Servlets.

Install and Setup Java

To run the Java Servlets we need a Servlet container like Apache Tomcat. 

Before going into detail of installing the servlet container we need to install Java and it is a prerequisite.

Download the latest version of JDK from Oracle download center. And install it. 

If the OS is Windows then the install is fairly straight forward, click next next next and finish. If it is Linux based distributions, believe me it is easier than that. Just a simple command will do. So once installation is done, set the JAVA_HOME variable,

set JAVA_HOME="C:\Program Files\Java\jdk1.8.0"

The GUI may be used to set the environment variable permanently. 

Go to ‘advanced system settings’ – > system properties –> advanced –> Environment Variables

Set-JAVA_HOME

If its Linux based,

setenv JAVA_HOME /usr/local/jdk1.8.0

Additionally you may also set the Java classpath

Install and Setup Apache Tomcat

Apache tomcat is the popular servlet container. It is simple, easy and powerful. 

Download the setup exe from the Apache site and as usual next next next.

Once the Apache Tomcat is installed as similar to JAVA_HOME, add a system variable as CATALINA_HOME for the home installation directory of Apache Tomcat.

set CATALINA_HOME="C:\Program Files\Apache Software Foundation\Tomcat 7.0"

Start / Stop Tomcat

In windows there will be an utility named “Monitor Tomcat” installed along with Apache Tomcat installation. 

It can be used to start and stop tomcat.

Start the Tomcat and go the URL http://localhost:8080/ in a web browser. 

A page similar to the following screen shot should be shown based on the version of Tomcat installed.

Tomcat-Start-Page

In Linux startup.sh and shutdown.sh scripts can be used to start and stop it.

Servlet API Classpath

To do development using Java servlets, Servlet API implementation is needed. 

In Tomcat installation lib folder, in my case “C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib” a Jar file named servlet-api.jar can be found. It should be added to the CLASSPATH to develop using Servlets. 

There are many ways to add this Jar to the classpath. 

This can be bundled along with the application itself or else it can be added to the system classpath as given in this linked Java classpath tutorial.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值