Something Different In Linux

Home » Tomcat » seminar on jsp and tomcat

seminar on jsp and tomcat

Posted by Rishikesh Vispute Categories: Tomcat

1] Introduction
1.1 Introduction Of Jsp
1.2 Introduction Of Tomcat
2] Requirements Of Hardware And Software Tomcat.
3] Installation Of  And Java And Tomcat
3.1] How To Install Java
3.2] How To Install Tomcat
4] Configuration of Tomcat and JSP
4.1] Structure of JSP
4.2] Configuration of Tomcat
5] How To Enable .Jsp Page Support For The Domain.
6] FAQ for the tomcat
6.1] Why Do You Have To Use Port 8080 To Use Tomcat?
7] Advantages Of Jsp Page
8] Some tomcat related command
9] Conclusion
10] Bibliography

1] Introduction
COMPUTER! The biggest invention by human being. There is not a single field in Which computers cannot be used. Various applications can be created using Computers. Basically there are 3 types of applications:

Those are:
Console applications: Using DOS & programming languages like C, C++.
Windows application Using WINDOWS & languages like Visual Basic, Visual C++, etc.
Web Applications: Using languages like ASP, JSP, .NET & JAVA.

WEB applications:
Among all technologies, the Internets has been fastest growing technology. Ever since its inception, the Internet has evolved exponentially. In the recent years, it has changed the way of conducting a business. Organization is increasingly becoming dependent on the Internet for sharing & accessing information. This Internet boon has changed the focus of application development from stand alone applications to distributed web application
Web applications are programs that can be executed either on a web server (in case of server side scripting) or on a web browser (in case of client side scripting). They enable a user to share & access information over the Internet & intranet.
1.1 Introduction Of JSP
Java Server Pages (JSP) is a technology introduced by Sun Microsystems aimed at building dynamic web content and web applications that are server and platform independent.
JSP pages allow developers to combine static HTML, XML content with code responsible for dynamic part.
Another benefit of using JSP is that the pages are compiled automatically as necessary when browser loads them. Other java technologies like Enterprise Java Beans(EJB), Remote Method Invocations(RMI) and JDBC can be called from within the JSP page, which provides greater flexibility in creating rich dynamic web content.
Java Server Pages (JSP) is a server-side technology that allows developers to create Web-based applications that can make use of components that are developed in the Java programming language, according to the JavaBeans specification. In some respects, it can be compared to server-side scripting languages such as ASP and PHP. JSP is similar to PHP in the C-style syntax of the Java language, but JSP was also designed to be extendable using components like ASP.
JSP Containers
JSP container can be defined as a middleware library that provides the compilation of JSP code into HTML page.
The common open source JSP containers are Apache Tomcat, Jetty, JBoss and Resin. Several popular commercial JSP containers are Web Logic (from BEA systems), Blazix, Web sphere(from IBM) and JBoss Application server(Commercial version). Tomcat is released under Apache license, and it’s main purpose is to compile JSP and servlets
1.2 Introduction Of Tomcat
Since Apache doesn’t support JSP out of the box, we need to add something else to the mix to provide that support. Unfortunately, JSP is too complicated to be supported by a simple Apache module; thus, we need to install an entirely new program to provide that support, then instruct Apache to forward requests for JSP pages to that program (note: this may sound like CGI, but it isn’t; just wait and see). The program we’ll be using is called Tomcat, and is also written by the Apache Group.
Tomcat, which is released under Apache license, is one of the more popular and widely used open source option for JSP container. Tomcat’s built in Jasper compiler does the actual compilation of JSP and Java servlets code. The latest available Tomcat version is 6.0.10 and it meets the latest JSP 2.1 specification. Although Tomcat can be used as a standalone HTTP server, it’s advisable to use it only as a JSP/servlets container and use a separate web server like Apache or Microsoft IIS. Apache is popular choice to be used together with Tomcat because Apache web server is more configurable, more robust, and faster than a standalone Tomcat server.

Purpose of Tomcat and JSP
Tomcat’s purpose is to provide standards-compliant support for servlets and JSP pages. The purpose of servlets and JSP pages is to generate web content such as HTML files or GIF files on demand using changing data. Web content that is generated on demand is said to be dynamic. On the other hand, web content that never changes and is served up as-is is called static. Web applications commonly include a great deal of static content, such as images or Cascading Style Sheets (CSS).

2] Requirements Of Hardware And Software for Tomcat.

3] Installation Of  And Java And Tomcat

3.1] How To Install Java
Download j2sdk-1.4.2 from Sun Download center Here I have used j2sdk-1_4_2_18-linux-i586-rpm.bin which will install j2sdk using RPMS and set the Path of JAVA_HOME automatically

#chmod +x j2sdk-1_4_2_09-linux-i586.bin

Now Check if Java is installed on the server using command java -version

[root@vps907 ~]# java -version
java version “1.6.0_07?
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing
3.2] How To Install Tomcat
Tomcat can be installed in any platforms, Linux, Windows or Macintosh as long as there’s Java runtime installed on the machine. Compared to some of the other servers and services like Apache and Samba, Tomcat is relatively easy to install and configure in any linux distribution.
To install Tomcat directly from the source, we need to have the latest JDK and ant tool available on the system. Depending on the linux distribution, JDK might already be installed in the system

You can install tomcat  manually as well as by using easy apache.
Download Tomcat
Now Download Tomcat from Apache Website and exract it
#cd /usr/local/
#tar -zxvf apache-tomcat-6.0.18.tar.gz
Create Symlink for the Tomcat Folder
#ln -s /usr/local/apache-tomcat-6.0.18 /usr/local/apache/tomcat

Install Tomcat
#cd apache-tomcat-6.0.18
#cd bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#chmod +x configure
#cp jsvc ..
#cd ..

4] Configuration of Tomcat and JSP

4.2] Tomcat Configuration

All the configuration files for Tomcat are located in /conf sub-folder. Generally, Tomcat is pretty easy to configure in the sense that not much tweaking of the configuration settings is required. Server.xml is the main configuration file for Tomcat and among other things, it allows administrator to change the default listening port from 8080 to something else (say 80). It also defines maximum number of requests allowed at a time. tomcat-users.xml file stores the usernames, passwords and specific roles for each usernames. For example, to use the tomcat-manager user interface from a browser, you need to have a user defined in this configuration file and be assigned the role of manager. Additionally, this file is used to verify username and password whenever session based authentication is implemented in any of the web applications. Web.xml configuration file contains mappings of servlets to URIs and each web application has it’s own web.xml file.
The directories each have a specific purpose:
The WEB-INF directory contains all non-public application files. None of these files can be directly accessed via an URL. Web applications can be configured by creating a file called web.xml, which is stored in this directory.
The WEB-INF/classes directory contains any .class files used by your web application. These include those for both servlets and non-servlet classes. If your classes or servlets are in packages, then you must create sub-directories to replicate the package directory structure and make sure the .class files are put into the correct directory. Do not put .jar files in this directory.
The WEB-INF/lib directory contains any .jar files needed by your application. Note, that if your application needs an XML parser then the parser .jar file should be added to this directory.
/bin – Startup, shutdown, and other scripts. The *.sh files (for Unix systems) are functional duplicates of the *.bat files (for Windows systems). Since the Win32 command-line lacks certain functionality, there are some additional files in here.
/conf – Configuration files and related DTDs. The most important file in here is server.xml. It is the main configuration file for the container.
/logs – Log files are here by default.
/webapps – This is where your webapps go.
Linking Apache and Tomcat with mod_jk
Now that you’ve got Apache and Tomcat running side by side, you need to link them together so that Apache can process JSP requests by handing them off to Tomcat. There are actually several ways to do this, and all involve installing an Apache module. The first option is to use mod_jk, which was designed specifically for Tomcat 3.x to work with various servers and uses a fairly efficient protocol for communication with Tomcat.

5] How To Enable .Jsp Page Support For The Domain.
If the .jsp page is showing coding instead of real webpage then you need to check the server settings such as
====================================================rroot@serveroot[~]#vi /etc/httpd/conf/httpd.conf
Search domain name and uncomment the following line.
Include “/usr/local/apache/conf/userdata/std/1/username/domainname/*.conf”
Save and exit
root@server[~]# cd /usr/local/apache/conf/userdata/std/1/
root@server[~]# mkdir username
root@server[~]# cd username
root@server[~]# mkdir domainname
root@server[~]# cd domainname
root@server[~]# vi cp_jkmount.conf
Enter the following code into the file cp_jkmount.conf.
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
Then check the entry into the tomcat configuration file.
root@server[~]# vi /usr/local/jakarta/tomcat/conf/server.xml
Open above file and add the following code at the end of the file.
<Host name=”domainname” appBase=”/home/username/public_html”>
<Context path=”” reloadable=”true” docBase=”/home/username/public_html” debug=”1″/>
<Context path=”/manager” debug=”0″ privileged=”true”

Save and exit
Then restart the tomcat

root@server[~]# /usr/local/jakarta/tomcat/bin/./
root@server[~]# /usr/local/jakarta/tomcat/bin/./
root@server[~]# /scripts/restartsrv tomcat
Then restart the httpd service

root@server[~]# /etc/init.d/httpd stop
root@server[~]# /etc/init.d/httpd startssl
6] FAQ for the tomcat

Q 1: Why do you have to use port 8080 to use tomcat?
Ans: The default port for http servers is 80. Tomcat defaults to using port 8080 instead to avoid an installation of tomcat automatically being seen as a public web server. Instead, tomcat be can setup and tested first using port 8080 and switched to port 80 when ready for normal use. In fact, tomcat is widely used as a development tool, so many users won’t want it to be a standard web server anyway – they will use it to develop web applications that are then installed on a production server elsewhere. On Unix systems there is also the issue that ports below 1024 are protected and can only be made available with root permission, so ordinary users would not be able to immediately use tomcat if it defaulted to port 80.
You can change tomcat’s default port by editing the conf/server.xml file. Look for the following Connector definition near the top of the file:
<!– Define a non-SSL HTTP/1.1 Connector on port 8080 –>
<Connector className=”org.apache.catalina.connector.http.HttpConnector”
port=”8080″ minProcessors=”5″ maxProcessors=”75″
enableLookups=”true” redirectPort=”8443″
acceptCount=”10″ debug=”0″ connectionTimeout=”60000″/>
To change the port number, change the 8080 to whatever port is needed. Note, that on Unix you will not be able to use a number below 1024 (unless you have root permissions on the machine you are using).

Q.2 What if I like to access the servlets directly via port 80 instead of using :portnumber on my URL?
You can do a trick, Edit apache virtual host entry and add the JkMount directive.
For example: I wanted to access a servlet which was under seed directory of my document root. I was able to access the servlet at<ServletNAME>
All I wanted to do is to simplify the above URL to look like :<ServletNAME>
This is not possible as appBase and DocBase are set to my domains Document root.
Hence I had make use of JkMount directive in VirtulHost entry as follows to change the appBase for the servler URI as follows :
<IfModule mod_jk.c>
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /seed/servlet/* ajp13
JkMount /seed/servlets/* ajp13
JkMount /manager/* ajp13
Now my URL works as needed.
7] Advantages Of Jsp Page

JSP provides much cleaner separation of presentation of logic and a simpler to write.
JSP are interpreted only once, to java byte code and re-interpreted only in the file is modified.
JSP are run on the entire main web server.
JSP provide better facilities for separation of page code and template data by means of java bean Enterprise Java Bean and custom tag libraries.
JSP can maintain state on the server between requests.
Doesn’t have to be loaded each time, once it has been initiated. JSP runs in a ready-loaded JVM as an extension to the web Server.
JSP provides specification web developers with frame work to create dynamic contents on the server using HTML, XML template and Java code which is secure, fast & independent of server platform.

8] Some tomcat related command
1) How to check version of Tomcat
root@server []# cd /usr/local/jakarta/tomcat/bin
root@server []# sh
2] How to start and stop tomcat
root@server []#/usr/local/jakarta/tomcat/bin/./  For Start
root@server []#/usr/local/jakarta/tomcat/bin/./ For Stop
root server[~]# /scripts/restartsrv tomcat
3] How to check tomcat error logs
4] Create symlinks for start and stop tomcat
ln -s /usr/local/jakarta/tomcat/bin/./ /etc/init.d/tomcatstart
ln -s /usr/local/jakarta/tomcat/bin/./ /etc/init.d/tomcatstop

I have concluded that the tomcat is necessary for the jsp. We can not run the .jsp page without tomcat.
9] Bibliography

4 Responses so far.

  1. Marzo 23rd says:

    Excellent way of describing, and nice article to take facts on the topic of my presentation
    subject matter, which i am going to convey in university.

  2. ipad3 says:

    Hi there! This is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in
    the same niche. Your blog provided us beneficial information
    to work on. You have done a extraordinary job!

Popular Posts

remove index.php fro

How to remove index.php from url in magento Ans : If you ...

PHP-Java bridge on p

  What is php-java bridge? The php-java bridge is the php ...

Set expiration for y

If you want to set the expiration to your site ...

Warning: Parameter 1

Error: Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a ...

domain pointing to e

If you domain uses external MX record and it is ...