Login.java
package View;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Login Page</title>");
out.println("</head>");
out.println("<body>");
out.println("<form action='Check' method='get'>");
out.println("<h3> Username </h3>");
out.println("<input type ='text' name='u_name'>");
out.println("<br>");
out.println("<h3> Password </h3>");
out.println("<input type ='password' name='pwd'>");
out.println("<br>");
out.println("<select>");
out.println("<option value='CSE'>Computer Science and
Engineering</option>");
out.println("<option value='ECE'>Electronics and
Commnunication</option>");
out.println("<option value='ME'>Mechanical</option>");
out.println("<option value='IC'>Instrumentation and Control</option>");
out.println("</select>");
out.println("</body>");
out.println("</html>");
out.println("<input type ='submit' value='Login'>");
out.println("</form>");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
Register.java
package View;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Register extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Registration Page</title>");
out.println("</head>");
out.println("<body>");
out.println("<form action='Display' method='get'>");
out.println("Name:");
out.println("<input type ='text' name = 'name'>");
out.println("Last Name:");
out.println("<input type ='text' name = 'lname'>");
out.println("Phone Number");
out.println("<input type ='text' name = 'pnumber'>");
out.println("<input type ='radio' name = 'gender' value = 'Male'>Male");
out.println("<input type ='radio' name = 'gender' value =
'Female'>Female");
out.println("<select name = 'course'>");
out.println("<option value='Computer Science and Engineering'>Computer
Science and Engineering</option>");
out.println("<option value='Electronics and Commnunication'>Electronics
and Commnunication</option>");
out.println("<option value='Mechanical Engineering'>Mechanical</option>");
out.println("<option value='Instrumentation and Control'>Instrumentation
and Control</option>");
out.println("</select>");
out.println("<input type = 'submit' value ='Register'>");
out.println("</form>");
out.println("</body>");
out.println("</html>")
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
Display.java
package View;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Display extends HttpServlet
{
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String name = request.getParameter("name");
String lname = request.getParameter("lname");
String phone = request.getParameter("pnumber");
String gender = request.getParameter("gender");
String course = request.getParameter("course");
out.println("<html>");
out.println("<head>");
out.println("<title>Info Display</title>");
out.println("</head>");
out.println("<body>");
out.println("<b>Name:</b>");
out.println(name);
out.println("<br>");
out.println("<b>Last Name:</b>");
out.println(lname);
out.println("<br>");
out.println("<b>Phone Number:</b>");
out.println(phone);
out.println("<br>");
out.println("<b>Gender:</b>");
out.println(gender);
out.println("<br>");
out.println("<b>Department:</b>");
out.println(course);
out.println("<br>");
out.println("</body>");
out.println("</html>");
}
finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}
public String getServletInfo()
{
return "Short description";
}
}
Error.java
package View;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Error extends HttpServlet
{
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Error Page</title>");
out.println("</head>");
out.println("<body>");
out.println("<form action='login'");
out.println("<h1>Something Was Wrong with your Username of
Password</h1>");
out.println("<br>");
out.println("<input type ='submit' value='Go Back'");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
Check.java
package Controller;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Check extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String name = request.getParameter("u_name");
String password = request.getParameter("pwd");
if(name.isEmpty() && password.isEmpty())
{
response.sendRedirect("Error");
}
else
{
response.sendRedirect("Register");
}
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
0 comments:
Post a Comment