0% found this document useful (0 votes)
29 views

WT Lab Program 4 & 5

web technologies lab program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

WT Lab Program 4 & 5

web technologies lab program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Ex. No.

INSTALLATION OF APACHE TOMCAT WEB SERVER

QUESTION:

Installation of Apache Tomcat web server

AIM:

To install Apache Tomcat Web Server

PROBLEM DESCRIPTION:

Apache Tomcat:
 Apache Tomcat is an open-source web server and servlet container
for Java code.
 Tomcat executes programs written in the Java programming
language, and it implements many Java EE specifications, including
Jakarta Servlet, Jakarta Server Pages, and others.
Prerequisites:
 Java JRE installed and configured
 Administrator privileges

PROCEDURE:

Step 1: Download Tomcat for Windows


To download the Tomcat installation file, follow the steps below:
1. Browse to the official Apache Tomcat website.
2. Locate the Download section and click the latest Tomcat
version available.
3. On the Download page, scroll down and locate the Binary
Distributions area.
4. In the Core list, depending on the installation type you prefer, click
the download link for the Windows Service Installer or
the 32bit/64bit Windows zip file.

1
Step 2: Install Tomcat
2
Install Tomcat via the Windows Service Installer for an automated
and wizard-guided experience.
The service installer installs the Tomcat service and runs itautomatically
when the system boots.
For a portable experience, install Tomcat using the zip file and avoid
installing the service.
Easily uninstall Tomcat when it is no longer needed by deleting the
Tomcat directory, or move it around when necessary.

Method 1: Install Tomcat Using the Windows Service Installer


Follow the steps below to install Tomcat using the Windows Service
Installer.
1. Open the downloaded Windows Service Installer file to start the
installation process.
2. In the Tomcat Setup welcome screen, click Next to proceed.

3. Read the License Agreement and if you agree to the terms, click I
Agree to proceed to the next step.

3
4. In the Tomcat component selection screen, choose Full in the
dropdown menu to ensure the wizard installs the Tomcat Host Manager
and Servlet and JSP examples web applications.
Alternatively, keep the default Normal installation type and click Next.

5. The next step configures the Tomcat server. For instance, enter
the Administrator login credentials or choose a
different connection port. When finished, click Next to proceed to the
next step.

4
6. The next step requires you to enter the full path to the JRE directory
on your system. The wizard auto-completes this if you have
previously set up the Java environment variables.
Click Next to proceed to the next step.

7. Choose the Tomcat server install location or keep the default one and
click Install.

5
8. Check the Run Apache Tomcat box to start the service after the
installation finishes.
Optionally, check the Show Readme box to see the Readme file. To
complete the installation, click Finish.

6
9. A popup window appears that starts the Tomcat service. After the
process completes, the window closes automatically. The Apache
Tomcat web server is now successfully installed

RESULT:

7
Ex. No. 5
(i) INVOKING SERVLETS FROM HTML FORM

QUESTION:

Write program in Java using Servlets:


i. To invoke servlets from HTML forms.

AIM:

To write a java program to invoke servlets from HTML form.

PROBLEM DESCRIPTION:

Java:
 Java is a widely used programming language for coding web
applications.
 Javais a multi-platform, object oriented and network centric language
that can be used as a platform in itself.
Servlet:
 Servlet is an application that is running on a server.
 Servlet is a Java programming language class that is used to extend
the capabilities of servers that host applications accessed by means
of a request-response programming model.
 There are two main types of servlets as Generic and HTTP servlet.
Elements required:
 <form>
 <script>
 <label>
 <input>
 <div>
 <style>
PROCEDURE:
client.html
1. Create a web page using HTML form that contains the fields such
as text, password and one submit button.
2. Set the URL of the server as the value of form’s action attribute.
3. Run the HTML program.
4. Submit the form data to the server.

8
server.java:
1. Define the class server that extends the property of the class
HttpServlet
2. Handle the request from the client by using the method service()
of HttpServlet class.
3. Get the parameter names from the HTML form by using the
method getParameterNames().
4. Get the parameter values from the HTML forms by using the
method getParameter().
5. Send the response to the client by using the method of PrintWriter
class.
CODING:
MySrv.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySrv extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
//Getting HTML parameters from Servlet
String username=request.getParameter("uname");
String password=request.getParameter("pwd");
if((username.equals("user")) && (password.equals("pswd")))
{
out.println(" <h1> Welcome to "+username);
}
else
{

9
out.println(" <h1> Registration success ");
out.println(" <a href='./index.html'> Click for Home page </a>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.close();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost( request,response);
}
}

Registration.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY bgcolor='#e600e6'>
<form action='./MySrv' method="post"><center><h1><u> Login Page
</u></h1>
<h2> Username : <input type="text" name="uname"/>
Password : <input type="password" name="pwd"/>
<input type="submit" value="click me"/>
</center>
</form>
</body>
</HTML>
web.xml:
<web-app>
<servlet>
<servlet-name>MySrv</servlet-name>
<servlet-class>MySrv</servlet-class>
10
</servlet>
<servlet-mapping>
<servlet-name>MySrv</servlet-name>
<url-pattern>/MySrv</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

OUTPUT:

RESULT:

11
Ex. No. 5
(ii) SESSION TRACKING USING HIDDEN FORM FIELDS

QUESTION:

Write program in Java using Servlets:


ii. Session tracking using hidden form fields and Session tracking for a
hit count

AIM:

To write a Java Program for Session Tracking Using Hidden Form


Fields.

PROBLEM DESCRIPTION:

Java:
 Java is a widely used programming language for coding web
applications.
 Javais a multi-platform, object oriented and network centric language
that can be used as a platform in itself.
Servlet:
 Servlet is an application that is running on a server.
 Servlet is a Java programming language class that is used to extend
the capabilities of servers that host applications accessed by means
of a request-response programming model.
 There are two main types of servlets as Generic and HTTP servlet.
Session ID:
 A session ID is a unique identification string usually a long, random
and alpha-numeric string, that is transmitted between the client and
the server.
 Session IDs are usually stored in the cookies, URLs (in case url
rewriting) and hidden fields of Web pages.
 Common mechanisms used for session tracking are Cookies,
SSLsessions, URL- rewriting
Elements required:
 <form>
 <script>
 <label>

12
 <input>
 <div>
 <style>
PROCEDURE:
1. Create a web page using HTML form that contains the fields such
as text, password and one submit button.
2. Set the URL of the server as the value of form’s action attribute.
3. Ask if the user wants to add more items or check out.
4. Include the current items as hidden fields so they'll be passed on
and submit to self.
CODING:
register.html:
<html>
<body bgcolor = "cyan">
<center>
<h1>WELCOME TO REGISTRATION PAGE</h1>
<form action="./registerone" METHOD="post">
Name: <input type="text" name = "name"><br><br>
Password: <input type="password" name="password"><br><br>
PROFESSION:
<select name="profession">
<option value="engineer">ENGINEER</option>
<option value="teacher">TEACHER</option>
<option value="businessman">BUSINESSMAN</option>
</select><br><br>
<input type="submit" value="REGISTER">
</form>
</center>
</body>
</html>

web.xml
<web-app>
<welcome-file-list>
<welcome-file>register.html</welcome-file>
13
</welcome-file-list>
<servlet>
<servlet-name>RegistrationServletOne</servlet-name>
<servlet-class>RegistrationServletOne</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServletOne</servlet-name>
<url-pattern>/registerone</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegistrationServletTwo</servlet-name>
<servlet-class>RegistrationServletTwo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServletTwo</servlet-name>
<url-pattern>/registertwo</url-pattern>
</servlet-mapping>
</web-app>

RegistrationServletOne.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegistrationServletOne extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
String name = request.getParameter("name");
14
String password = request.getParameter("password");
String profession = request.getParameter("profession");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor = wheat>");
out.println("<center>");
out.println("<h1>COMPLETE THE REGISTRATION</h1>");
out.println("<form action = ./registertwo method = post");
out.println("<input type = hidden name = name value =" + name +
">");
out.println("<input type = hidden name = password value =" +
password + ">");
out.println("<input type = hidden name = profession value =" +
profession + ">");
out.println("EMAIL ID:<input type =text name = email><br><br>");
out.println("PHONE NO:<input type =text name = cell><br><br>");
out.println("<input type =submit value=registernow>");
out.println("</center>");
out.println("</body></html>");
out.close();
}
}

RegistrationServletTwo.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegistrationServletTwo extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse
response)
15
throws ServletException, IOException
{
String name = request.getParameter("name");
String password = request.getParameter("password");
String profession = request.getParameter("profession");
String email = request.getParameter("email");
String cell = request.getParameter("cell");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor = wheat>");
out.println("<center>");
out.println("<h1>REGISTRATION SUCCESSFUL..........</h1>");
out.println("</center>");
out.println("</body></html>");
out.close();
}
OUTPUT:

16
RESULT:

17

You might also like