0% found this document useful (0 votes)
25 views11 pages

Web Practical

The document contains several Java servlet programs and JSP examples, including a 'Hello World' servlet and a servlet for displaying today's date. It also features a login page using servlets, which checks user credentials and displays a welcome message or a login failure message. Additionally, it includes JSP code for printing 'Hello World' and displaying the current date and time.

Uploaded by

angelin272004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

Web Practical

The document contains several Java servlet programs and JSP examples, including a 'Hello World' servlet and a servlet for displaying today's date. It also features a login page using servlets, which checks user credentials and displays a welcome message or a login failure message. Additionally, it includes JSP code for printing 'Hello World' and displaying the current date and time.

Uploaded by

angelin272004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2

SERVLET PROGRAM TO PRINT HELLO WORLD

import java.io.IOException;
import java.io.Print Writer;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HtpServletResponse;
public class helloworld extends HttpServlet {
protected void doGet(HttpServletRequest request,
HtpServletResponse response) throws ServletException,1OException

Print Writer pw-response.get Writer();

pw.println("<!DOCTYPE html>);
pw.printin("<html>");

pw.println("<head>");

pw.println("<title>hello world</title>");
pw.println("</head>":
pw.println("<body>");

pw.println("<hl><center>SERVLET PROGRAM TO PRINT</center></hl>):


pw.println("<h2><center>HELLO WORLD</center></h2>"):
pw.println("<body>");
pw.println("<html>");
OUTPUT

Ae locallhost S'pigm1/hetletld Seasch..


heio workd

SERVLET PROGRAM TO PRINT


HELL0 WORLD
SERVLET PROGRAM TO PRINT TODAY'S DATE

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class todaydate extends HttpServlet

protected void doGet(HttpServletRequest request,


HttpServletResponse response)throws ServletException,IOException

PrintWriter pw-response.get Writer();


Date today -new Date ();

pw.printn("<html>");

pw.println("<body bgcolor-pink <body>":


pw.println("<title>Todays date</title>");
pw.println("<hl><center>SERVLET PROGRAM TO PRINT TODAY'S
DATE</center></hl>");

pw.println("<h2><center>"+today+"</center></h2<htm>"):

}
OUTPUT

p lecalhest.S5gnl/todayite Seorch..
Tedays date

SERVILET PROGRAMI TO PRINT TODAY'S DATE


Thu Feb 29 08:37:09 IST 2024

7
Login Page using servlet
Index.html
<html>
<head>

<title>LOGIN</title>
<meta charset-"UTF-8">
<meta name-"viewport" content="width=device-width, initial-scale-1.0">
</head>

<body><center><hl>Login Page using Servlet</hl>


<form action="http://Mlocalhost:8080/Divine/NewServlet3">
Enter User Id <input type-"text" name-"txtId"><br<br>
Enter Password <inputtype="password" name-"txtPass"><br><br>
<input type-"Reset">
<input type-"Submit" value-"Click To Login">
</form></center>
</body>
<htm>

NewServlet3.java
import java.io.IOException;
import java.io.Print Writer;
import javax.servlet.ServletException;
import javax.servlet.htp.HttpServlet;
import javax.servlet.htp.HtpServletRequest;
import javax.servlet.htp.HttpServletResponse;
public class NewServlet3 extends HttpServlet {
protected void doGet(HtpServletRequest request,
response)throws ServletException, IOException HttpServletResponse
12

PrintWriter pw=response.getWriter);
pw.println("<!DOCTYPE htm"):
pw.println("<htm|>");
pw.println("<head>");
pw.println("<title>Servlet loginservlet</title>"):
pw.println("<head>"):
pw.println("<body>";
String uname-request.getParameter("txtId");
String upass=request.getParameter("txtPass");
if(uname.equals("Elsa")& &upass.equals("12345"))
pw.println("<body bgcolor-white>");
pw.println("<hl><center> Welcome "tunamet"</center></hl>");
} else

{
if(uname.equals("Anna") &&upass.equals("123"))
pw.println("<body bgcolor-white>"):
pw.println("<hl> Welcome "funame+"</hl>"):
else

pw.printin("<body bgcolor-white>");
pw.println("<hl><enter>Login Failed<center></hl>");
pw.println("</body>");
pw.println("</html>");
13

Output:

Servlet loginservlet X +

(O localhost:8080/Divine/NewServ... p A

Welcome Elsa

31C Sunny O ENG23


04-03-2

LOGIN

O localhost:808O/Divine/index.ht... A

LoginPage using Servlet


Enter User IdiElsa

Enter Password

Reset Click To Login Ë

1223
JSP PROGRAM TO PRINT HELLO WORLD

<%@page contentType="texthtml" pageEncoding="UTF-8"%>


<!DOCTYPE htm>

<htm>

<head>

<title>JSP Page</title>
<head>

<body bgcolor-"pink">

<% out.println("<h l><center>JSP PROGRAM TOPRINT HELLO


WORLD</center></hl>);%>
<% out.println("<h 1><center>HELLO WORLD!</center></hl>"); %>

<body>
<<htm>
OUTPUT:

WORLD
JSP PROGRAM TO PRINT HELLO
IELLO WORLD!
DISPLAY CURRENT DATE AND TIME USING JSP

<o@page import = "java.io.* java.util.*javax.servlet.*" %>


<htm>

<head>

<title> DISPLAYCURRENT DATE & TIME USING JSP</title>


</head>

<body bgcolor= "pink">


<pallign ="center" style-color:grey;count-size:30;HTML <p>

<center>

<hl>DISPLAY CURRENT DATE & TIME USING JSP</h1>


</center>

Date date = new Date():

out.print( "<h2 align =\"centerl">" +date.toString)+"</h2>"):


%>

</body>
<html>
OUTPUT:

DISPLAY CURRENT DATE & TIME USING JSP


Tue Mar 05 11:16:32 IST 2024

You might also like