Servlet

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class DemoServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType(“text/html”);//setting the content typePrintWriter pw=res.getWriter();//get the stream to write data
pw.println(“<html><body>”);
pw.println(“Welcome to servlet”);
pw.println(“</body></html>”);
pw.close();//closing the stream
}}
<web-app>
<servlet>
<servlet-name>
Bhuvi</servlet-name>
<servlet-class>
DemoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
Bhuvi</servlet-name>
<url-pattern>
/welcome</url-pattern>
</servlet-mapping>
</web-app>

JSP

<%! int var=10; %>
<% 
String s="Kamesh";
System.out.println(s);
%>
<% num1=num1+num2 %>
<% -- JSP Comments %>

JSP Life Cycle

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="admin.jsp"%>
<%@ page import="com.ContactPage.ConnectionProvider"%>
<%@ page import="java.sql.*"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DashBoard</title>
</head>
<body>
<hr/>

<form action="Archieve.jsp" method="post">
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
if (session.getAttribute("session") == null) {
response.sendRedirect("login.jsp");
}
try {
Connection connection = ConnectionProvider.getConnection();
Statement statement = connection.createStatement();
String query = "Select * from contactus where isactive=true ORDER BY timestamp";
ResultSet resultset = statement.executeQuery(query);
%>
<h1>Active Requests</h1>
<table border="1">
<tr>
<td>Full Name</td>
<td>E-Mail</td>
<td>Message</td>
<td>Time Zone</td>
</tr>
<%
while (resultset.next()) {
%>
<tr>
<td><%=resultset.getString(1)%></td>
<td><%=resultset.getString(2)%></td>
<td><%=resultset.getString(3)%></td>
<td><%=resultset.getString(4)%></td>

<td><input type="submit" value="Archieve"> <input
type="hidden" value=<%="Archieve" + resultset.getInt(6)%>
name="Archieve"></td>
<%
}
} catch (Exception exception) {
out.println(exception);
}
%>

</table>
</form>

<br>
<hr />
<h1>Archive Requests</h1>
<form action="UnArchieve.jsp" method="post">
<%
try {

Connection connection = ConnectionProvider.getConnection();
Statement statement = connection.createStatement();
String query = "Select * from contactus where isactive='false' ORDER BY timestamp";
ResultSet resultset = statement.executeQuery(query);
%>
<table border="1">
<tr>
<td>Full Name</td>
<td>E-Mail</td>
<td>Message</td>
<td>Time Zone</td>
</tr>
<%
while (resultset.next()) {
%>
<tr>
<td><%=resultset.getString(1)%></td>
<td><%=resultset.getString(2)%></td>
<td><%=resultset.getString(3)%></td>
<td><%=resultset.getString(4)%></td>
<td><input type="submit" value="UnArchieve"> <input
type="hidden" value=<%="UnArchieve" + resultset.getInt(6)%>
name="unArchieve"></td>

</tr>
<%
}
} catch (Exception exception) {
out.println(exception);
}
%>
</table>
</form>
</body>
</html>

Conclusion