servlets. installation of tomcat 7.0.35 2) install tomcat 7.0.35 while creating this ppt, latest...

33
SERVLETS

Upload: randolf-page

Post on 23-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

SERVLETS

Page 2: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

Installation Of Tomcat 7.0.35

2) Install Tomcat 7.0.35

http://tomcat.apache.org/

While creating this ppt, latest version of Tomcat was downloaded from :

http://apache.techartifact.com/mirror/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.exe

Documentation :

http://tomcat.apache.org/tomcat-7.0-doc/servletapi/index.html

1) Before Installing Tomcat, first install the latest version of Java JDK.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

While creating this ppt, latest version of JDK 7 was downloaded from : http://download.oracle.com/otn-pub/java/jdk/7u11-b21/jdk-7u11-windows-x64.exe

Documentation :

http://docs.oracle.com/javase/7/docs/api/index.html

Page 3: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

Installing Apache Tomcat

Page 4: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 5: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

Please select all the options.

Page 6: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 7: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 8: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 9: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 10: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 11: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

3) Setting Of Environment Variables.(Setting of Environment Variables is required only for the first time.)

- Right Click On My Computer.

- Select Properties

- Click On Advanced Tab.

- And then click on Environment Variables.

Page 12: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 13: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

4) Environment Variables Dialog Box will appear.

Page 14: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

5) Now there are four Environment Variables that we have to set. If the variables are already present, don’t erase the contents, just put a semicolon “;” and then write your path. (For Eg : C:\Program Files;C:\WINDOWS). If Variable Is Not Present, Select New. See further slides for clarifaction.

In this case, since PATH is already present, to add your own path, select PATH, and click on “Edit”. Put a semicolon at end, and then put your own path.

If PATH was not present, select “New”, And add your path.

Page 15: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

Following Environment variables are to be set by user(copy paste the path from address bar).

1) PATH = The path of bin directory of JAVA.

2) JAVA_HOME = Top level directory of JAVA.

3) CATALINA_HOME = Top level directory of Tomcat 7.0

4) CLASSPATH = servlet-api.jar file of Folder : “\Apache Software Foundation\Tomcat 7.0\lib”

(In This Case)

1) PATH = C:\Program Files\Java\jdk1.7.0_11\bin

2) JAVA_HOME = C:\Program Files\Java\jdk1.7.0_11

3) CATALINA_HOME = C:\Program Files\Apache Software Foundation\Tomcat 7.0

4) CLASSPATH =C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;.

(Note a “dot & semicolon” at end of CLASSPATH”)

Page 16: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

Note : (When setting the CLASSPATH variable, PLEASE put ;. (semicolon & dot )after the path. For Example :C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;.If you don’t do this, you wont be able to run any java files with main().)

Page 17: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

6) To verify whether Environment variables are set properly or not.Go to command prompt and verify using “set” command.

Page 18: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

7) EXECUTING SERVLET PROGRAMS :

Write the program in Notepad and save it in directory :“C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF\classes”

Note :

(If you save the file in bin directory of java, and then compile it, then save the .class file in “C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF\classes”)

Page 19: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

SAMPLE PROGRAM TO DISPLAY A TEXT IN A BROWSER

HelloServlet.java file

import java.io.*;import javax.servlet.*;

public class HelloServlet extends GenericServlet{

public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException

{response.setContentType("text/html");PrintWriter pw = response.getWriter();pw.println("<B>Hello Servlet !!!");pw.close();

}}

Page 20: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

8) Set the current directory in command prompt as

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF\classes

by typing “cd (space)“ in command prompt and dragging the “classes” folder in Command Prompt.

OR

You can also type the whole path.

Page 21: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

9) Compile the java file using “javac”

After compiling, it will create a .class file

Page 22: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

10) Editing web.xml file: The web.xml file is present in

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF

Important Note :

(Before editing web.xml file, create a backup of that file somewhere else so that if something wrong is written in that file, you can again replace it.)

Open the web.xml file using Notepad for editing.

Page 23: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

Following file will open.

Page 24: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

11) Find <servlet> tag, copy the first 4 lines (till </servlet>) and paste it just below it. Then change the name of class to your own class (Here, HelloServlet).

For Example : (First 4 lines are already present, copy it, paste it just below it and change its class name to your own class name. Don’t leave any blank lines between corresponding servlet tags.) <servlet> <servlet-name>ServletToJsp</servlet-name> <servlet-class>ServletToJsp</servlet-class> </servlet> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>HelloServlet</servlet-class> </servlet>

Page 25: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 26: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

12) Then Find <servlet-mapping> tag, copy the first 4 lines (till </servlet-mapping> and paste it just below it. Then change the name of class to your own class (Here, HelloServlet).

For Example :

<servlet-mapping> <servlet-name>CompressionFilterTestServlet</servlet-name> <url-pattern>/CompressionTest</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/HelloServlet</url-pattern> </servlet-mapping>

Please notice that there is a slash ‘/’ before HelloServlet in url pattern.

13) Then save the file, and close it.

Page 27: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded
Page 28: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

14) Starting Tomcat 7.0

Go to Start -> All Programs -> Apache Tomcat 7.0 Tomcat7 -> Configure Tomcat

Page 29: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

15) Following window will open. Click on Start. And After that, on OK.

Page 30: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

16) Now open a web browser and type : http://localhost:8080/

If Apache Tomcat opens, then it means you've setup Tomcat successfully.

Page 31: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

17) Now Type :

http://localhost:8080/examples/YourProgramName

Here : http://localhost:8080/examples/HelloServlet

Page 32: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded

18) After executing servlets, close the browser and then again open Configure Tomcat.

Then click on “Stop”

Page 33: SERVLETS. Installation Of Tomcat 7.0.35 2) Install Tomcat 7.0.35  While creating this ppt, latest version of Tomcat was downloaded