Creating a JSP Page & Environment Setup

To create the first jsp page, write some html code as given below, and save it by .jsp extension. We have save this file as index.jsp. Put it in a folder and paste the folder in the web-apps directory in apache tomcat to run the jsp page.Lets create index.jsp file to display Hello World!! and also add scriptlet code.

<html>
<body>>
<h1> Hello World!!</h1>
 <% out.print(34+23); %>
</body>
</html>

To run this jsp file firstly set up the environment for running this example.
Setting up Java Development Kit
This step involves downloading an implementation of the Java Software Development Kit (SDK) and setting up PATH environment variable appropriately.

You can download SDK from Oracle’s Java site: Java SE Downloads.

Once you download your Java implementation, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

Setting up Web Server: Tomcat
A number of Web Servers that support JavaServer Pages and Servlets development are available in the market. Some web servers are freely downloadable and Tomcat is one of them.

Apache Tomcat is an open source software implementation of the JavaServer Pages and Servlet technologies and can act as a standalone server for testing JSP and Servlets and can be integrated with the Apache Web Server.
1. Download latest version of Tomcat from http://tomcat.apache.org/.
2. After downloading unzip the file
For example in C:Program Files (x86)Apache Software FoundationTomcat 7.0. on windows, or /usr/local/Tomcat 7.0. on Linux/Unix and create CATALINA_HOME environment variable pointing to these locations.

Tomcat can be started by executing the following commands on windows machine:
C:Program Files (x86)Apache Software FoundationTomcat 7.0binstartup.bat

After a successful startup, the default web applications included with Tomcat will be available by visiting http://localhost:8080/. If everything is fine then it should display following result:

Tomcat can be started by executing the following commands on windows machine:

C:Program Files (x86)Apache Software FoundationTomcat 7.0binshutdown.bat

Setting up CLASSPATH
Since servlets are not part of the Java Platform, Standard Edition, you must identify the servlet classes to the compiler.

Now copy index.jsp file into  
C:Program Files (x86)Apache Software FoundationTomcat 7.0webapps
And restart the server and hit the following url.
http://localhost:8080/index/index.jsp

<<Previous <<   || Index ||   >>Next >>
Previous
Next