Presentation is loading. Please wait.

Presentation is loading. Please wait.

SERVLETS.

Similar presentations


Presentation on theme: "SERVLETS."— Presentation transcript:

1 SERVLETS

2 Installation Of Tomcat 7.0.35
1) Before Installing Tomcat, first install the latest version of Java JDK. While creating this ppt, latest version of JDK 7 was downloaded from : Documentation : 2) Install Tomcat While creating this ppt, latest version of Tomcat was downloaded from : Documentation :

3 Installing Apache Tomcat

4

5 Please select all the options.

6

7

8

9

10

11 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.

12

13 4) Environment Variables Dialog Box will appear.

14 5) Now there are four Environment Variables that we have to set
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.

15 Following Environment variables are to be set by user(copy paste the path from address bar).
PATH = The path of bin directory of JAVA. JAVA_HOME = Top level directory of JAVA. CATALINA_HOME = Top level directory of Tomcat 7.0 CLASSPATH = servlet-api.jar file of Folder : “\Apache Software Foundation\Tomcat 7.0\lib” (In This Case) PATH = C:\Program Files\Java\jdk1.7.0_11\bin JAVA_HOME = C:\Program Files\Java\jdk1.7.0_11 CATALINA_HOME = C:\Program Files\Apache Software Foundation\Tomcat 7.0 CLASSPATH =C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;. (Note a “dot & semicolon” at end of CLASSPATH”)

16 Note : (When setting the CLASSPATH variable, PLEASE put ;
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().)

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

18 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”)

19 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(); }

20 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.

21 9) Compile the java file using “javac”
After compiling, it will create a .class file

22 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.

23 Following file will open.

24 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-name>HelloServlet</servlet-name> <servlet-class>HelloServlet</servlet-class>

25

26 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-name>HelloServlet</servlet-name> <url-pattern>/HelloServlet</url-pattern> Please notice that there is a slash ‘/’ before HelloServlet in url pattern. 13) Then save the file, and close it.

27

28 14) Starting Tomcat 7.0 Go to Start -> All Programs -> Apache Tomcat 7.0 Tomcat7 -> Configure Tomcat

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

30 16) Now open a web browser and type : http://localhost:8080/
If Apache Tomcat opens, then it means you've setup Tomcat successfully.

31 17) Now Type : http://localhost:8080/examples/YourProgramName
Here :

32 18) After executing servlets, close the browser and then again open Configure Tomcat.
Then click on “Stop”

33


Download ppt "SERVLETS."

Similar presentations


Ads by Google