Wednesday 10 April 2013

Servlet internal question paper for web technologies

Internal Question paper for WEB TECHNOLOGIES
1.     
  (a) Implement link styles in html program (b) write a simple servlet program
2.       (a) write a login form validation(user name and password) using external java script. (b)Write a servlet program for the life cycle of the servlet
3.       (A) Create a dynamic table by using java script (b) how do you do the session tracking in servlets, write a example program for cookies
4.       Create a webpage layout by using division tag in html (b) write a example program for CSS id and Css class
5.       Write any html program with css by applying external style sheet (b) write a servlet program for initializing and reading parameters( that is initialize the parameters in xml file and read from servlet program)
6.       Write any html program with java script by applying external java script (b) write a simple servlet program
7.       Write any html program using lists (b)create a simple web application by using servlet
8.       Display a time table using html table tag (b) create a login screen in html and store the username and password in server and display on the browser
9.       (a) write a program for student registration form using html (b)
10.   (a) Example program for span tag in html
11.   (a) write a example program on java script events
12.   (a) write a xml file with xml schema
13.   (a) write a xml file with xml DTD (B) Design a html program using Layers in html

14.   What are the lists? Write a html program for each of the list types

Tuesday 2 April 2013

Example program for Life cycle of servlet

Example program for Life cycle of servlet



Steps:
1. create the folder structure
2. set the classpath
3. compile the servlet programs
4. deploy the application in server
5. run the web application in the browser


1. Create the folder structure 

(i) create the folder with any name (Ex: LifeCycleServlet)
(ii) create the html file
(iii) servlet program
(iii) create the WEB-INF folder


(ii) create the html file :  Home.html

<html>
 <head>
  <title>LifeCycleServlet</title>
 </head>
 <body>
  <form action="myFirstServlet" method="get">
   <br/><br/><br/>
   <center>
    <input type="submit" value="invoke LifeCycle"/>
   </center>
  </form>
 </body>
</html>

//output


(ii) write the servlet program
//LCServlet.java
package com.rajendra.servlets;
import javax.servlet.*;


import java.io.IOException;
import java.io.PrintWriter;
public class LCServlet implements Servlet
{
 public void init(ServletConfig sc)
 {
  config=sc;
  System.out.println("in init");
 }
 public void service(ServletRequest req,ServletResponse res) throws ServletException,IOException
 {
  PrintWriter out=res.getWriter();
  out.println("Hello from LifeCycleServlet");
 }
 public void destroy()
 {
  System.out.println("in destroy");
 }
 public String getServletInfo()
 {
  return "LifeCycleServlet";
 }
 public ServletConfig getServletConfig()
 {
  return config;
 }
 private ServletConfig config;
}

/*
set the classpath to compile the servlet program
//D:\\LifeCycleServlet>set CLASSPATH=C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;.;
//D:\\LifeCycleServlet>javac -d . LCServlet.java
*/
                                                       (iii) create the WEB-INF folder

1.  create WEB-INF folder in LifeCycleServlet folder,go to WEB-INF folder
2.  web.xml file
3. create classes folder
4. lib folder


->now copy the class file of LifeCycleServlet folder of LCServlet.java
-> paste in to classes folder of WEB-INF folder

                                                                        4. web.xml file

1. create a note pad in WEB-INF folder
2. type the following in that note pad
3. save it as web.xml file

<web-app>
<servlet>
<servlet-name>ls</servlet-name>
  <servlet-class>com.rajendra.servlets.LCServlet</servlet-class>
  </servlet>

<servlet-mapping>
  <servlet-name>ls</servlet-name>
  <url-pattern>/myFirstServlet</url-pattern>
  </servlet-mapping>
</web-app>

4. save the above file and save it as web.xml in WEB-INF folder
5. go to command prompt and prepare the war file (this is optional)

D:\\LifeCycleServlet>jar cvf LCS.war * .class

4. deploy the application in server

Steps:
1. copy the folder(LifeCycleServlet) or Copy the WAR file
2. deploy into the server
(i) go to tomcat server installed directory(assume that we have installed c : drive)
3. double click on C:
4.  click on Program Files
5. Go to TomCat Server 6.0 (latest version)
6.  open 'webapps' folder
7. paste your folder(application) ie. LifeCycleServlet


5.   Start the Tomcat Server

1.  go to C:\Program Files\Apache Software Foundation\Tomcat 6.0
2. open the bin folder
3.  double click on tomcat6.exe file
4. now we will see the following (see the figure)

6.   Executing (running) the servlet program

1. go to any web browser
2. type http://localhost:8888/ (here 8888 is the port number)

3. double click on Tomcat Manager
4. select your application from the list
5. http://localhost:8888/LifeCycleServlet/
6. and type the home.html at the end of the URL
eX:http://localhost:8888/LifeCycleServlet/Home.html

7. double click on the button i.e invoke LifeCycle


You may like the following posts: